Tabnine Logo
ExprUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
ExprUtils
in
org.apache.jena.sparql.util

Best Java code snippets using org.apache.jena.sparql.util.ExprUtils (Showing top 20 results out of 315)

Refine searchRefine arrow

  • Expr
  • NodeValue
origin: apache/jena

/**
 * A convenience method to make an expression from a string.  Evaluates the 
 * expression with respect to the current query.
 * 
 * @param expression The expression to parse.
 * @return the Expr object.
 * @throws QueryParseException on error.
 */
public Expr makeExpr(String expression) throws QueryParseException
{
  return ExprUtils.parse(query, expression, true);
}
origin: SmartDataAnalytics/jena-sparql-api

@Override
public Node apply(Binding binding, Long rowNum) {
  NodeValue nv = ExprUtils.eval(expr, binding);
  Node result = nv.asNode();
  return result;
}
origin: apache/jena

protected Expr asExpr(Node n) {
  return ExprUtils.nodeToExpr(n) ;
}
origin: apache/jena

public static void expr(String exprStr, Binding binding)
{
  try {
    Expr expr = ExprUtils.parse(exprStr, ARQConstants.getGlobalPrefixMap()) ;
    evalPrint(expr, binding) ;
  }
  catch (QueryParseException ex)
  {
    System.err.println("Parse error: "+ex.getMessage()) ;
    return ;
  }
}

origin: apache/jena

static void testDouble(String exprString, Node result, double delta) {
  Expr expr = ExprUtils.parse(exprString, pmap);
  NodeValue actual = expr.eval(null, new FunctionEnvBase());
  NodeValue expected = NodeValue.makeNode(result);
  // Note that we don't test lexical form because we can get mismatches
  // between how things like doubles are expressed
  if (NodeValue.sameAs(expected, actual))
    return;
  testDouble(exprString, expected.getDouble(), delta); ;
}

origin: ch.epfl.bluebrain.nexus.org.topbraid/shacl

if(expr != null && (!expr.isVariable() || binding.contains(expr.asVar()))) {
  NodeValue x = expr.eval(binding, env);
  if(x != null) {
    String paramName;
      paramName = "arg" + (i + 1);
    bindings.add(paramName, model.asRDFNode(x.asNode()));
    if(cachable) {
      paramsForCache[i] = x.asNode();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IndentedWriter iOut = new IndentedWriter(bos);
    ExprUtils.fmtSPARQL(iOut, expr, new SerializationContext(model));
    iOut.flush();
    sb.append(bos.toString());
  sb.append(FmtUtils.stringForNode(result.asNode(), model));
origin: apache/jena

static NodeValue eval(String exprString) {
  Expr expr = ExprUtils.parse(exprString, pmap);
  NodeValue result = expr.eval(null, new FunctionEnvBase());
  return result ;
}
  
origin: apache/jena

private static void test_exprSprintf_tz_possibilites(String nodeStr, String... possible) {
  String exprStr = "afn:sprintf('%1$tm %1$te,%1$tY', "+NodeValue.makeDateTime(nodeStr).toString()+")" ;
  Expr expr = ExprUtils.parse(exprStr) ;
  NodeValue r = expr.eval(null, LibTestExpr.createTest()) ;
  assertTrue(r.isString()) ;
  String s = r.getString() ;
  // Timezones! The locale data can be -1, 0, +1 from the Z day.
  boolean b = false ;
  for (String poss : possible ) {
    if ( poss.equals(s) )
      b = true ;
  }
  assertTrue(b) ;
}

origin: apache/jena

pmap.setNsPrefix("ex", "http://example/ns#") ;
Expr expr = ExprUtils.parse(exprStr, pmap) ;
if ( actionPrint )
    ExprUtils.fmtSPARQL(iOut, expr);
    iOut.ensureStartOfLine();
    NodeValue r = expr.eval(null, env) ;
    Node n = r.asNode() ;
    String s = NodeFmtLib.displayStr(n) ;
    System.out.println(s) ;
origin: SmartDataAnalytics/jena-sparql-api

public static Pair<Expr, Expr> optimizeFunctionOpConstant(Expr a, Expr b)
{
  NodeValue constant = null;
  ExprFunction function = null;
  boolean swapArgs = false;
  UnaryOperator<Expr> factory;
  if(a.isConstant() && b.isFunction()) {
    constant = a.getConstant();
    function = b.getFunction();
  } else if(a.isFunction() && b.isConstant()) {
    function = a.getFunction();
    constant = b.getConstant();
    swapArgs = true;
  } else {
    return Pair.create(a, b);
  }
  factory = inverseFunctionManager.getInverse(b.getFunction().getFunctionIRI());
  if(factory == null) {
    return Pair.create(a, b);
  }
  Expr invConst = factory.apply(constant);
  Expr resultConst = org.apache.jena.sparql.util.ExprUtils.eval(invConst);
  Expr resultFunc = function.getArg(1);
  return createPair(resultConst, resultFunc, swapArgs);
}
origin: SmartDataAnalytics/jena-sparql-api

  expr = ExprUtils.parse(str, prefixMapping);
} else {
  String p = prefixMapping.expandPrefix(str);
  Node np = NodeFactory.createURI(p);
  expr = new E_Equals(new ExprVar(Vars.p), NodeValue.makeNode(np));
origin: apache/jena

private static void testNumberFormat(String expression, String expected) {
  Expr expr = ExprUtils.parse(expression) ;
  NodeValue r = expr.eval(null, LibTestExpr.createTest()) ;
  Assert.assertTrue(r.isString());
  Assert.assertEquals(expected, r.getString()) ;
}

origin: SmartDataAnalytics/Sparqlify

  if(a.equals(SparqlifyConstants.nvTypeError)) {
    newExpr = SparqlifyConstants.nvTypeError;
  } else {
    if(evaledArg.equals(SparqlifyConstants.nvTypeError)) {
      return SparqlifyConstants.nvTypeError;
if(exprTransformer != null && newExpr.isFunction()) {
  tmp = exprTransformer.transform(newExpr.getFunction());
  result = ExprUtils.eval(tmp);
} catch(ExprNotComparableException e) {
  return SparqlifyConstants.nvTypeError;
origin: SmartDataAnalytics/Sparqlify

  Set<Var> exprVars = expr.getVarsMentioned();
  for(Var var : exprVars) {
    if(!binding.contains(var)) {
      if(usedVars.containsAll(expr.getVarsMentioned())) {
        continue;
      } else if(usedVars.equals(expr.getVarsMentioned())) {
        throw new RuntimeException("Multiple expressions binding the variable (ambiguity) " + bindingVar + ": " + entry.getValue());
      } else if(!expr.getVarsMentioned().containsAll(usedVars)) {
    value = ExprUtils.eval(expr, binding);
Node resultValue = value == null ? null : value.asNode();
origin: apache/jena

static void testDouble(String exprString, double expected, double delta) {
  Expr expr = ExprUtils.parse(exprString, pmap);
  NodeValue actual = expr.eval(null, new FunctionEnvBase());
  assertTrue("Not a double: "+actual, actual.isDouble() ) ; 
  double result = actual.getDouble() ;
  
  // Because Java floating point calculations are woefully imprecise we
  // are in many cases simply testing that the differences between the
  // values are within a given delta
  if ( Double.isInfinite(expected) ) {
    assertTrue("Expected INF: Got "+result, Double.isInfinite(result)) ;
    return ;
  }
  
  if ( Double.isNaN(expected) ) {
    assertTrue("Expected NaN: Got "+result, Double.isNaN(result)) ;
    return ;
  }
  double difference = Math.abs(result - expected);
  assertTrue("Values not within given delta " + delta + ": Expected = " + expected + " : Actual = " + actual,
      difference <= delta);
}
origin: SmartDataAnalytics/Sparqlify

public Boolean determineSatisfiability(Expr expr) {
  /*
  BindingMap bindingMap = new BindingMap();
  for(Entry<Var, Node> entry : binding.entrySet()) {
    bindingMap.add(entry.getKey(), entry.getValue());
  }*/
  if(binding.keySet().containsAll(expr.getVarsMentioned())) {
    try {
      NodeValue value = ExprUtils.eval(expr, bindingMap);
      return value.getBoolean();
    } catch(Exception e) {
      // Evaluation of the expression failed despite all variables were bound
      // Satisfiability unknown
      System.err.println(e);
      return null;
    }
  }
  else if(expr instanceof E_LogicalNot) {
    Boolean tmp = determineSatisfiability(((E_LogicalNot)expr).getArg());
    return tmp == null ? null : !tmp;
  }
  else if(expr instanceof E_Equals) {
    E_Equals e = (E_Equals)expr;
    RestrictionSetImpl a = getRestriction(e.getArg1());
    RestrictionSetImpl b = getRestriction(e.getArg2());
    return determineSatisfiabilityEquals(a, b);
  } else {
    return null;
  }
}
origin: SmartDataAnalytics/jena-sparql-api

  Entry<Var, NodeValue> c = ExprUtils.extractConstantConstraint(expr);
  if(c != null && c.getKey().equals(s)) {
    Node n = c.getValue().asNode();
    concretePredicates.add(n);
  } else {
ExprList exprs = new ExprList();
for(Node node : concretePredicates) {
  Expr expr = org.apache.jena.sparql.util.ExprUtils.nodeToExpr(node);
  exprs.add(expr);
origin: apache/jena

Expr target = ExprUtils.nodeToExpr(entry.getKey());
Node n = values.get(entry.getKey());
Var v = entry.getKey();
  if (n.isVariable()) {
    v = Var.alloc(n);
    if (target.equals(e)) {
      e = ExprUtils.nodeToExpr(n);
origin: SmartDataAnalytics/Sparqlify

and = and && ExprUtils.eval(expr, binding).getBoolean();
if(and == false) {
  break;
origin: apache/jena

public static void fmtSPARQL(IndentedWriter iOut, ExprList exprs)
{
  fmtSPARQL(iOut, exprs, FmtUtils.sCxt()) ;
}
org.apache.jena.sparql.utilExprUtils

Javadoc

Misc support for Expr

Most used methods

  • parse
  • eval
  • nodeToExpr
  • fmtSPARQL
  • evalPrint
  • expr
  • exprPrefix

Popular in Java

  • Making http requests using okhttp
  • getExternalFilesDir (Context)
  • onRequestPermissionsResult (Fragment)
  • getSystemService (Context)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • JComboBox (javax.swing)
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now