Beispiel #1
0
  @Override
  public QueryIterator execEvaluated(
      final Binding binding,
      PropFuncArg argSubject,
      Node predicate,
      PropFuncArg argObject,
      ExecutionContext execCxt) {
    // check subject is a variable.
    if (!argSubject.getArg().isVariable()) throw new QueryExecException("Subject not a variable");

    final Var var = Var.alloc(argSubject.getArg());

    if (!argObject.getArg().isLiteral()) throw new QueryExecException("Subject not a literal");

    String searchTerm = argObject.getArg().getLiteralLexicalForm();
    Search search = searchEngine();
    Iterator<String> x = search.search(searchTerm);
    Iter<String> iter = Iter.iter(x);
    QueryIterator qIter =
        new QueryIterPlainWrapper(
            iter.map(
                (item) -> {
                  return BindingFactory.binding(binding, var, NodeFactory.createURI(item));
                }));
    return qIter;
  }
  protected AbstractIterHashJoin(
      JoinKey joinKey,
      QueryIterator probeIter,
      QueryIterator streamIter,
      ExecutionContext execCxt) {
    super(probeIter, streamIter, execCxt);

    if (joinKey == null) {
      QueryIterPeek pProbe = QueryIterPeek.create(probeIter, execCxt);
      QueryIterPeek pStream = QueryIterPeek.create(streamIter, execCxt);

      Binding bLeft = pProbe.peek();
      Binding bRight = pStream.peek();

      List<Var> varsLeft = Iter.toList(bLeft.vars());
      List<Var> varsRight = Iter.toList(bRight.vars());
      joinKey = JoinKey.createVarKey(varsLeft, varsRight);
      probeIter = pProbe;
      streamIter = pStream;
    }

    this.joinKey = joinKey;
    this.iterStream = streamIter;
    this.hashTable = new HashProbeTable(joinKey);
    this.iterCurrent = null;
    buildHashTable(probeIter);
  }
Beispiel #3
0
  private QueryIterator resultsToQueryIterator(
      Binding binding,
      Node s,
      Node score,
      Node literal,
      Collection<TextHit> results,
      ExecutionContext execCxt) {
    Var sVar = Var.isVar(s) ? Var.alloc(s) : null;
    Var scoreVar = (score == null) ? null : Var.alloc(score);
    Var literalVar = (literal == null) ? null : Var.alloc(literal);

    Function<TextHit, Binding> converter =
        (TextHit hit) -> {
          if (score == null && literal == null)
            return sVar != null
                ? BindingFactory.binding(binding, sVar, hit.getNode())
                : BindingFactory.binding(binding);
          BindingMap bmap = BindingFactory.create(binding);
          if (sVar != null) bmap.add(sVar, hit.getNode());
          if (scoreVar != null) bmap.add(scoreVar, NodeFactoryExtra.floatToNode(hit.getScore()));
          if (literalVar != null) bmap.add(literalVar, hit.getLiteral());
          return bmap;
        };

    Iterator<Binding> bIter = Iter.map(results.iterator(), converter);
    QueryIterator qIter = new QueryIterPlainWrapper(bIter, execCxt);
    return qIter;
  }
Beispiel #4
0
 /* Count the triples for the graph.find */
 public static long countTriples(Graph graph, Node s, Node p, Node o) {
   ExtendedIterator<Triple> iter = graph.find(s, p, o);
   try {
     return Iter.count(iter);
   } finally {
     iter.close();
   }
 }
 @Override
 public void deleteAny(Node g, Node s, Node p, Node o) {
   Iterator<Quad> iter = find(g, s, p, o);
   List<Quad> list = Iter.toList(iter);
   for (Quad q : list) {
     delete(q);
   }
 }
Beispiel #6
0
 /**
  * Choose a graph from a DatasetGraph. If it's the union, provide a union graph (not always the
  * best way to deal with union).
  *
  * @param dataset
  * @param graphNode
  * @return Graph
  */
 protected static Graph chooseGraph(DatasetGraph dataset, Node graphNode) {
   if (graphNode == null) return dataset.getDefaultGraph();
   else if (Var.isVar(graphNode))
     throw new NotImplemented("Choosing a graph OpExecutorStage.executeBlockFilter[Variable]");
   else if (graphNode == Node.ANY)
     throw new NotImplemented("OpExecutorMain.executeBlockFilter[Node.ANY]");
   else if (Quad.isUnionGraph(graphNode)) {
     // TODO Check this!  Work needed here to consolidate union graph handling.
     List<Node> graphs = Iter.toList(dataset.listGraphNodes());
     return new GraphUnionRead(dataset, graphs);
   } else return dataset.getGraph(graphNode);
 }
  @Test
  public void dataset_05() {
    String graphName = "http://example/";
    Dataset ds = createFixed();
    ds.addNamedModel(graphName, model1);
    ds.replaceNamedModel(graphName, model2);
    assertTrue(ds.containsNamedModel(graphName));

    List<String> x = Iter.toList(ds.listNames());
    assertEquals(1, x.size());
    assertEquals(graphName, x.get(0));

    assertFalse(model1.isIsomorphicWith(ds.getNamedModel(graphName)));
    assertTrue(model2.isIsomorphicWith(ds.getNamedModel(graphName)));
  }
  @Test
  public void dataset_04() {
    String graphName = "http://example/";
    Dataset ds = createFixed();
    ds.addNamedModel(graphName, model1);
    assertTrue(ds.containsNamedModel(graphName));

    List<String> x = Iter.toList(ds.listNames());
    assertEquals(1, x.size());
    assertEquals(graphName, x.get(0));

    assertFalse(model1.isIsomorphicWith(ds.getDefaultModel()));
    Model m = ds.getNamedModel(graphName);

    assertNotNull(m);
    assertTrue(model1.isIsomorphicWith(m));

    ds.removeNamedModel(graphName);
    // Not getNamedModel and test for null as some datasets are "auto graph creating"
    assertFalse(ds.containsNamedModel(graphName));
  }
 /** Abbreviate, crudely, URI in strings, leaving only their last component. */
 public static <T> String printAbbrevList(List<T> objs) {
   String x = Iter.asString(objs, "\n");
   return printAbbrev(x);
 }
Beispiel #10
0
 @Override
 public Iterator<Pair<NodeId, Node>> all() {
   // Better would be to convert the spill file format.
   return Iter.concat(base.all(), nodeTableJournal.all());
 }
Beispiel #11
0
 /* Count the matches to a pattern across the dataset  */
 public static long countTriples(DatasetGraph dsg, Node s, Node p, Node o) {
   Iterator<Quad> iter = dsg.find(Node.ANY, s, p, o);
   return Iter.count(iter);
 }
Beispiel #12
0
 public Collection<V> values() {
   return Iter.toList(flatten());
 }
 private static Set<SqlTable> tables(Set<SqlColumn> cols) {
   return Iter.toSet(Iter.map(cols.iterator(), SqlColumn::getTable));
 }