Search in sources :

Example 6 with NodeValueString

use of org.apache.jena.sparql.expr.nodevalue.NodeValueString in project jena by apache.

the class ExprFactoryTest method asListTest.

@Test
public void asListTest() {
    ExprList lst = factory.asList("?foo", "http://example.com", Converters.quoted("hello"), 1, 5L, 3.14f, 6.28d, Var.alloc("bar"), null, factory.rand());
    assertEquals(10, lst.size());
    assertEquals(new ExprVar("foo"), lst.get(0));
    // assertEquals( new ExprVar( "foo" ), lst.get(0));
    assertEquals(new NodeValueString("hello"), lst.get(2));
    assertEquals(1, lst.get(3).getConstant().asNode().getLiteralValue());
    assertEquals(5, lst.get(4).getConstant().asNode().getLiteralValue());
    assertEquals(3.14f, lst.get(5).getConstant().asNode().getLiteralValue());
    assertEquals(6.28, lst.get(6).getConstant().asNode().getLiteralValue());
    assertEquals(new ExprVar("bar"), lst.get(7));
    assertEquals(Expr.NONE, lst.get(8));
    assertEquals(new E_Random(), lst.get(9));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) ExprList(org.apache.jena.sparql.expr.ExprList) E_Random(org.apache.jena.sparql.expr.E_Random) NodeValueString(org.apache.jena.sparql.expr.nodevalue.NodeValueString) Test(org.junit.Test)

Example 7 with NodeValueString

use of org.apache.jena.sparql.expr.nodevalue.NodeValueString in project webofneeds by researchstudio-sat.

the class SparqlMatcherUtils method createSearchQuery.

public static Op createSearchQuery(String searchString, Var resultName, int hops, boolean disjunctive, boolean tokenize) {
    Var textSearchTarget = Var.alloc("textSearchTarget");
    Optional<Op> union = IntStream.range(1, hops + 1).mapToObj(hopCount -> makePathBGPPattern(resultName, textSearchTarget, hopCount, op -> {
        Expr filterExpression = Arrays.stream(tokenize ? searchString.toLowerCase().split(" ") : new String[] { searchString.toLowerCase() }).<Expr>map(searchPart -> new E_StrContains(new E_StrLowerCase(new ExprVar(textSearchTarget)), new NodeValueString(searchPart))).reduce((left, right) -> disjunctive ? new E_LogicalOr(left, right) : new E_LogicalAnd(left, right)).orElse(new NodeValueBoolean(true));
        return OpFilter.filterBy(new ExprList(filterExpression), op);
    })).reduce((op1, op2) -> new OpUnion(op1, op2));
    Op maintriple = new OpTriple(new Triple(resultName, RDF.type.asNode(), WON.Atom.asNode()));
    Op mainOp = union.isPresent() ? OpJoin.create(maintriple, union.get()) : maintriple;
    return mainOp;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Transformer(org.apache.jena.sparql.algebra.Transformer) RDF(org.apache.jena.vocabulary.RDF) ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) OpModifier(org.apache.jena.sparql.algebra.op.OpModifier) OpVisitorBase(org.apache.jena.sparql.algebra.OpVisitorBase) BasicPattern(org.apache.jena.sparql.core.BasicPattern) ExprList(org.apache.jena.sparql.expr.ExprList) Random(java.util.Random) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) OpJoin(org.apache.jena.sparql.algebra.op.OpJoin) OpProject(org.apache.jena.sparql.algebra.op.OpProject) Walker(org.apache.jena.sparql.algebra.walker.Walker) OpUnion(org.apache.jena.sparql.algebra.op.OpUnion) Function(java.util.function.Function) OpDistinct(org.apache.jena.sparql.algebra.op.OpDistinct) OpService(org.apache.jena.sparql.algebra.op.OpService) OpConditional(org.apache.jena.sparql.algebra.op.OpConditional) E_LogicalOr(org.apache.jena.sparql.expr.E_LogicalOr) OpList(org.apache.jena.sparql.algebra.op.OpList) Op(org.apache.jena.sparql.algebra.Op) TransformCopy(org.apache.jena.sparql.algebra.TransformCopy) E_StrLowerCase(org.apache.jena.sparql.expr.E_StrLowerCase) ExprVar(org.apache.jena.sparql.expr.ExprVar) WONMATCH(won.protocol.vocabulary.WONMATCH) WON(won.protocol.vocabulary.WON) OpLeftJoin(org.apache.jena.sparql.algebra.op.OpLeftJoin) Op2(org.apache.jena.sparql.algebra.op.Op2) NodeValueString(org.apache.jena.sparql.expr.nodevalue.NodeValueString) Triple(org.apache.jena.graph.Triple) Expr(org.apache.jena.sparql.expr.Expr) E_NotExists(org.apache.jena.sparql.expr.E_NotExists) OpVisitorByTypeBase(org.apache.jena.sparql.algebra.OpVisitorByTypeBase) OpSlice(org.apache.jena.sparql.algebra.op.OpSlice) Var(org.apache.jena.sparql.core.Var) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) E_LogicalAnd(org.apache.jena.sparql.expr.E_LogicalAnd) NodeValueBoolean(org.apache.jena.sparql.expr.nodevalue.NodeValueBoolean) OpTriple(org.apache.jena.sparql.algebra.op.OpTriple) OpMinus(org.apache.jena.sparql.algebra.op.OpMinus) Optional(java.util.Optional) OpOrder(org.apache.jena.sparql.algebra.op.OpOrder) E_StrContains(org.apache.jena.sparql.expr.E_StrContains) OpFilter(org.apache.jena.sparql.algebra.op.OpFilter) OpReduced(org.apache.jena.sparql.algebra.op.OpReduced) ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) OpUnion(org.apache.jena.sparql.algebra.op.OpUnion) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) NodeValueString(org.apache.jena.sparql.expr.nodevalue.NodeValueString) Triple(org.apache.jena.graph.Triple) OpTriple(org.apache.jena.sparql.algebra.op.OpTriple) E_LogicalAnd(org.apache.jena.sparql.expr.E_LogicalAnd) NodeValueBoolean(org.apache.jena.sparql.expr.nodevalue.NodeValueBoolean) Expr(org.apache.jena.sparql.expr.Expr) ExprList(org.apache.jena.sparql.expr.ExprList) E_StrLowerCase(org.apache.jena.sparql.expr.E_StrLowerCase) E_LogicalOr(org.apache.jena.sparql.expr.E_LogicalOr) OpTriple(org.apache.jena.sparql.algebra.op.OpTriple) E_StrContains(org.apache.jena.sparql.expr.E_StrContains)

Aggregations

NodeValueString (org.apache.jena.sparql.expr.nodevalue.NodeValueString)7 Test (org.junit.Test)6 Expr (org.apache.jena.sparql.expr.Expr)4 ExprList (org.apache.jena.sparql.expr.ExprList)2 ExprVar (org.apache.jena.sparql.expr.ExprVar)2 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Function (java.util.function.Function)1 IntStream (java.util.stream.IntStream)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 ResourceImpl (org.apache.jena.rdf.model.impl.ResourceImpl)1 Op (org.apache.jena.sparql.algebra.Op)1 OpVisitorBase (org.apache.jena.sparql.algebra.OpVisitorBase)1 OpVisitorByTypeBase (org.apache.jena.sparql.algebra.OpVisitorByTypeBase)1 TransformCopy (org.apache.jena.sparql.algebra.TransformCopy)1 Transformer (org.apache.jena.sparql.algebra.Transformer)1 Op2 (org.apache.jena.sparql.algebra.op.Op2)1 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)1