use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.
the class AbstractReferenceInputConverter method connect.
protected static URLConnection connect(final Reference ref) throws UnconvertibleObjectException {
final String brutHref;
if (ref == null || (brutHref = ref.getHref()) == null) {
throw new UnconvertibleObjectException("Null reference given.");
}
final URL href;
try {
final String decoded = URLDecoder.decode(brutHref, "UTF-8");
href = new URL(decoded);
} catch (UnsupportedEncodingException | MalformedURLException ex) {
throw new UnconvertibleObjectException("Invalid reference href: " + brutHref, ex);
}
final URLConnection connection;
try {
connection = href.openConnection();
} catch (IOException ex) {
throw new UnconvertibleObjectException("Cannot connect to reference url:" + href, ex);
}
for (final Reference.Header header : ref.getHeader()) {
connection.addRequestProperty(header.getKey(), header.getValue());
}
addBody(connection, ref.getBody(), ref.getBodyReference());
return connection;
}
use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.
the class BooleanToReferenceConverter method convert.
@Override
public Reference convert(final Boolean source, final Map<String, Object> params) throws UnconvertibleObjectException {
if (params.get(TMP_DIR_PATH) == null) {
throw new UnconvertibleObjectException("The output directory should be defined.");
}
if (source == null) {
throw new UnconvertibleObjectException("The output data should be defined.");
}
Reference reference = new Reference();
reference.setMimeType((String) params.get(MIME));
reference.setEncoding((String) params.get(ENCODING));
reference.setSchema((String) params.get(SCHEMA));
reference.setMimeType("text/plain");
reference.setEncoding("UTF-8");
reference.setSchema(null);
final String randomFileName = UUID.randomUUID().toString();
try {
// create file
final Path literalFile = buildPath(params, randomFileName);
IOUtilities.writeString(String.valueOf(source), literalFile);
final String relLoc = getRelativeLocation(literalFile, params);
reference.setHref((String) params.get(TMP_DIR_URL) + "/" + relLoc);
} catch (IOException ex) {
throw new UnconvertibleObjectException("Error occure during image writing.", ex);
}
return reference;
}
use of com.google.api.expr.v1alpha1.Reference in project dishevelled-bio by heuermh.
the class ReassemblePaths method call.
@Override
public Integer call() throws Exception {
BufferedReader reader = null;
PrintWriter writer = null;
try {
reader = reader(inputGfa1File);
writer = writer(outputGfa1File);
final PrintWriter w = writer;
final List<Path> paths = new ArrayList<Path>();
final ListMultimap<String, Traversal> traversalsByPathName = ArrayListMultimap.create();
Gfa1Reader.stream(reader, new Gfa1Listener() {
@Override
public boolean record(final Gfa1Record gfa1Record) {
if (gfa1Record instanceof Path) {
Path path = (Path) gfa1Record;
paths.add(path);
} else if (gfa1Record instanceof Traversal) {
Traversal traversal = (Traversal) gfa1Record;
traversalsByPathName.put(traversal.getPathName(), traversal);
} else {
Gfa1Writer.write(gfa1Record, w);
}
return true;
}
});
for (Path path : paths) {
List<Traversal> traversals = traversalsByPathName.get(path.getName());
Collections.sort(traversals, new Comparator<Traversal>() {
@Override
public int compare(final Traversal t0, final Traversal t1) {
return t0.getOrdinal() - t1.getOrdinal();
}
});
List<Reference> segments = new ArrayList<Reference>();
List<String> overlaps = new ArrayList<String>();
for (Traversal traversal : traversals) {
if (segments.isEmpty()) {
segments.add(traversal.getSource());
}
segments.add(traversal.getTarget());
if (traversal.hasOverlap()) {
overlaps.add(traversal.getOverlap());
}
}
Gfa1Writer.write(new Path(path.getName(), segments, overlaps.isEmpty() ? null : overlaps, path.getAnnotations()), w);
}
return 0;
} finally {
try {
reader.close();
} catch (Exception e) {
// ignore
}
try {
writer.close();
} catch (Exception e) {
// ignore
}
}
}
use of com.google.api.expr.v1alpha1.Reference in project cel-java by projectnessie.
the class Env method residualAst.
/**
* ResidualAst takes an Ast and its EvalDetails to produce a new Ast which only contains the
* attribute references which are unknown.
*
* <p>Residual expressions are beneficial in a few scenarios:
*
* <ul>
* <li>Optimizing constant expression evaluations away.
* <li>Indexing and pruning expressions based on known input arguments.
* <li>Surfacing additional requirements that are needed in order to complete an evaluation.
* <li>Sharing the evaluation of an expression across multiple machines/nodes.
* </ul>
*
* <p>For example, if an expression targets a 'resource' and 'request' attribute and the possible
* values for the resource are known, a PartialActivation could mark the 'request' as an unknown
* interpreter.AttributePattern and the resulting ResidualAst would be reduced to only the parts
* of the expression that reference the 'request'.
*
* <p>Note, the expression ids within the residual AST generated through this method have no
* correlation to the expression ids of the original AST.
*
* <p>See the PartialVars helper for how to construct a PartialActivation.
*
* <p>TODO: Consider adding an option to generate a Program.Residual to avoid round-tripping to an
* Ast format and then Program again.
*/
public Ast residualAst(Ast a, EvalDetails details) {
Expr pruned = pruneAst(a.getExpr(), details.getState());
String expr = astToString(parsedExprToAst(ParsedExpr.newBuilder().setExpr(pruned).build()));
AstIssuesTuple parsedIss = parse(expr);
if (parsedIss.hasIssues()) {
throw parsedIss.getIssues().err();
}
if (!a.isChecked()) {
return parsedIss.ast;
}
AstIssuesTuple checkedIss = check(parsedIss.ast);
if (checkedIss.hasIssues()) {
throw checkedIss.getIssues().err();
}
return checkedIss.ast;
}
use of com.google.api.expr.v1alpha1.Reference in project cel-java by projectnessie.
the class Checker method setReference.
void setReference(Expr.Builder e, Reference r) {
Reference old = references.get(e.getId());
if (old != null && !old.equals(r)) {
throw new IllegalStateException(String.format("Reference already exists for expression: %s(%d) old:%s, new:%s", e, e.getId(), old, r));
}
references.put(e.getId(), r);
}
Aggregations