org.apache.jena.graph.Graph.add()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.apache.jena.graph.Graph.add()方法的一些代码示例,展示了Graph.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.add()方法的具体详情如下:
包路径:org.apache.jena.graph.Graph
类名称:Graph
方法名:add

Graph.add介绍

[英]Add the triple t (if possible) to the set belonging to this graph
[中]将三重t(如果可能)添加到属于此图的集合中

代码示例

代码示例来源:origin: org.aksw.jena-sparql-api/jena-sparql-api-mapper

@Override
public void writeValue(Object value, Node subject, Node predicate,
    Graph outputGraph) {
  if(value != null) {
    // value must be a string
    String iri = value.toString();
    Node o = NodeFactory.createURI(iri);
    Triple t = new Triple(subject, predicate, o);
    outputGraph.add(t);
  }
}

代码示例来源:origin: org.apache.jena/jena-core

private static Graph make(int N) {
  Graph graph = Factory.createGraphMem();
  for ( int i = 0 ; i < N ; i++ ) {
    Triple t = GraphTestBase.triple("a P 'x"+i+"'");
    graph.add(t);
  }
  return graph ;
}

代码示例来源:origin: apache/jena

/**
 * Test basic rule operations - simple AND rule 
 */
public void testBaseRules1() {    
  List<Rule> rules = Rule.parseRules("[r1: (?a r ?c) <- (?a p ?b),(?b p ?c)]");        
  Graph data = Factory.createGraphMem();
  data.add(new Triple(a, p, b));
  data.add(new Triple(b, p, c));
  data.add(new Triple(b, p, d));
  Reasoner reasoner =  createReasoner(rules);
  InfGraph infgraph = reasoner.bind(data);
  TestUtil.assertIteratorValues(this, 
    infgraph.find(null, r, null), 
    new Object[] {
      new Triple(a, r, c),
      new Triple(a, r, d)
    } );
}

代码示例来源:origin: apache/jena

@Test(expected=UnsupportedOperationException.class)
public void zero_add_2() {
  DatasetGraph dsg = DatasetGraphZero.create();
  dsg.getDefaultGraph().add(triple);
}

代码示例来源:origin: apache/jena

@Test public void rdfjson_escapes()
{
  Graph g = GraphFactory.createGraphMem();
  Node s = NodeFactory.createBlankNode();
  Node p = NodeFactory.createURI("http://predicate");
  g.add(new Triple(s, p, NodeFactory.createLiteral("quote \" character")));
  g.add(new Triple(s, p, NodeFactory.createLiteral("new \n\r lines")));
  g.add(new Triple(s, p, NodeFactory.createLiteral("tab \t character")));
  test(g);
}

代码示例来源:origin: apache/jena

/**
 * Test example hybrid rule.
 */
public void testHybrid1() {
  Graph data = Factory.createGraphMem();
  data.add(new Triple(a, p, b));
  data.add(new Triple(p, ty, s));
  String rules =
  "[r1: (?p rdf:type s) -> [r1b: (?x ?p ?y) <- (?y ?p ?x)]]";
  InfGraph infgraph = createInfGraph(rules, data);
  TestUtil.assertIteratorValues(this, 
     infgraph.find(null, p, null), new Object[] {
       new Triple(a, p, b),
       new Triple(b, p, a)
     } );
}

代码示例来源:origin: org.apache.jena/jena-core

/** 
 * Generic test operation.
 * @param ruleSrc the source of the rules
 * @param triples a set of triples to insert in the graph before the query
 * @param query the Triple to search for
 * @param results the array of expected results
 */
private void doTest(String ruleSrc, Triple[] triples, Triple query, Object[] results) {
  List<Rule> rules = Rule.parseRules(ruleSrc);
  Graph data = Factory.createGraphMem();
  for ( Triple triple : triples )
  {
    data.add( triple );
  }
  InfGraph infgraph =  makeInfGraph(rules, data);
  TestUtil.assertIteratorValues(this, infgraph.find(query), results); 
}

代码示例来源:origin: apache/jena

@Test(expected=AddDeniedException.class)
public void find_union_04() {
  DatasetGraphBaseFind dsgx = (DatasetGraphBaseFind)dsg ;
  dsgx.getUnionGraph().add(q4.asTriple());
}

代码示例来源:origin: apache/jena

@Test public void testUpdateScript5()
{
  DatasetGraph gStore = getEmptyDatasetGraph() ;
  script(gStore, "data-2.ru") ;
  
  
  Graph g = GraphFactory.createPlainGraph() ;
  Node b = org.apache.jena.graph.NodeFactory.createBlankNode() ;
  
  g.add(new Triple(s, p, b)) ;
  g.add(new Triple(b, q, v)) ;
  assertTrue(g.isIsomorphicWith(gStore.getDefaultGraph())) ;
}

代码示例来源:origin: apache/jena

/**
 * Test basic rule operations - simple AND rule check with tabling.
 */
public void testBaseRules3() {    
  List<Rule> rules = Rule.parseRules("[rule: (?a rdfs:subPropertyOf ?c) <- (?a rdfs:subPropertyOf ?b),(?b rdfs:subPropertyOf ?c)]");        
  Reasoner reasoner =  createReasoner(rules);
  Graph data = Factory.createGraphMem();
  data.add(new Triple(p, sP, q) );
  data.add(new Triple(q, sP, r) );
  data.add(new Triple(p, sP, s) );
  data.add(new Triple(s, sP, t) );
  data.add(new Triple(a,  p, b) );
  InfGraph infgraph = reasoner.bind(data);
  TestUtil.assertIteratorValues(this, 
    infgraph.find(null, RDFS.subPropertyOf.asNode(), null), 
    new Object[] {
      new Triple(p, sP, q),
      new Triple(q, sP, r),
      new Triple(p, sP, s),
      new Triple(s, sP, t),
      new Triple(p, sP, t),
      new Triple(p, sP, r)
    } );
}

代码示例来源:origin: apache/jena

/**
   * Test example hybrid rules for rdfs.
   */
  public void testHybridRDFS2() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, p, b));
    data.add(new Triple(p, sP, r));
    data.add(new Triple(r, RDFS.range.asNode(), C1));
    String rules = 
  "[rdfs3:  (?p rdfs:range ?c)  -> [(?y rdf:type ?c) <- (?x ?p ?y)] ]" + 
  "[rdfs6:  (?p rdfs:subPropertyOf ?q) -> [ (?a ?q ?b) <- (?a ?p ?b)] ]" ; 
    InfGraph infgraph = createInfGraph(rules, data);
//        ((FBRuleInfGraph)infgraph).setTraceOn(true);
    TestUtil.assertIteratorValues(this, 
       infgraph.find(b, ty, C1), new Object[] {
         new Triple(b, ty, C1)
       } );
  }

代码示例来源:origin: apache/jena

/**
 * Internals of makeList.
 */
private static Node doMakeList(Node[] nodes, int next, Graph graph) {
  if (next < nodes.length) {
    Node listNode = NodeFactory.createBlankNode();
    graph.add(new Triple(listNode, RDF.Nodes.first, nodes[next]));
    graph.add(new Triple(listNode, RDF.Nodes.rest, doMakeList(nodes, next+1, graph)));
    return listNode;
  } else {
    return RDF.Nodes.nil;
  }
}

代码示例来源:origin: apache/jena

/** 
 * Generic test operation.
 * @param ruleSrc the source of the rules
 * @param triples a set of triples to insert in the graph before the query
 * @param query the Triple to search for
 * @param results the array of expected results
 */
private void doTest(String ruleSrc, Triple[] triples, Triple query, Object[] results) {
  List<Rule> rules = Rule.parseRules(ruleSrc);
  Graph data = Factory.createGraphMem();
  for ( Triple triple : triples )
  {
    data.add( triple );
  }
  InfGraph infgraph =  makeInfGraph(rules, data);
  TestUtil.assertIteratorValues(this, infgraph.find(query), results); 
}

代码示例来源:origin: apache/jena

private static Graph make(int N) {
  Graph graph = Factory.createGraphMem();
  for ( int i = 0 ; i < N ; i++ ) {
    Triple t = GraphTestBase.triple("a P 'x"+i+"'");
    graph.add(t);
  }
  return graph ;
}

代码示例来源:origin: apache/jena

@Test
public void add_2()
{
  distinct.add(SSE.parseTriple("(<x> <p> 'ZZZ')"));
  distinct.add(SSE.parseTriple("(<x> <p> 'ZZZ')"));
  assertEquals(1, count(distinct));
}

代码示例来源:origin: apache/jena

@Test
public void dataset2() {
  TL.exec((ds) -> {
    Graph g1 = ds.getDefaultModel().getGraph() ;
    Graph g2 = ds.getNamedModel("http://example/").getGraph() ;
    g1.add(new Triple(n0, n1, n2)) ;
    assertTrue(g1.contains(n0, n1, n2)) ;
    assertFalse(g2.contains(n0, n1, n2)) ;
  }) ;
}

代码示例来源:origin: apache/jena

/**
 * Test basic rule operations - simple AND/OR with tabling.
 */
public void testBaseRules4() {    
  Graph data = Factory.createGraphMem();
  data.add(new Triple(a, r, b));
  data.add(new Triple(b, r, c));
  data.add(new Triple(b, r, b));
  data.add(new Triple(b, r, d));
  List<Rule> rules = Rule.parseRules(
          "[r1: (?x p ?y) <- (?x r ?y)]" +
          "[r2: (?x p ?z) <- (?x p ?y), (?y r ?z)]" 
          );        
  Reasoner reasoner =  createReasoner(rules);
  InfGraph infgraph = reasoner.bind(data);
  TestUtil.assertIteratorValues(this, 
    infgraph.find(a, p, null), 
    new Object[] {
      new Triple(a, p, b),
      new Triple(a, p, d),
      new Triple(a, p, c)
    } );
}

代码示例来源:origin: apache/jena

private Node getSkolem(Node x, Node y) {
  String rules =  "[r1: (?n p ?x) (?n q ?y) makeSkolem(?s ?x ?y) -> (?n s ?s)]";
  Graph data = Factory.createGraphMem();
  data.add(new Triple(n1, p, x));
  data.add(new Triple(n1, q, y));
  InfGraph infgraph = createInfGraph(rules, data);
  return infgraph.find(n1, s, Node.ANY).next().getObject();
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

@Override
public void writeValue(Object value, Node subject, Node predicate,
    Graph outputGraph) {
  if(value != null) {
    // value must be a string
    String iri = value.toString();
    Node o = NodeFactory.createURI(iri);
    Triple t = new Triple(subject, predicate, o);
    outputGraph.add(t);
  }
}

代码示例来源:origin: apache/jena

/** 
 * Generic test operation.
 * @param ruleSrc the source of the rules
 * @param tabled the predicates that should be tabled
 * @param triples a set of triples to insert in the graph before the query
 * @param query the Triple to search for
 * @param results the array of expected results
 */
private void doTest(String ruleSrc, Node[] tabled, Triple[] triples, Triple query, Object[] results) {
  List<Rule> rules = Rule.parseRules(ruleSrc);
  Graph data = Factory.createGraphMem();
  for ( Triple triple : triples )
  {
    data.add( triple );
  }
  InfGraph infgraph =  makeInfGraph(rules, data, tabled);
  TestUtil.assertIteratorValues(this, infgraph.find(query), results); 
}

相关文章