org.openrdf.model.Model类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(150)

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

Model介绍

[英]An RDF Model, represented as a java.util.Set of Statements with predictable iteration order.

Additional utility functionality for working with Model objects is available in the org.openrdf.model.util.Models utility class.
[中]RDF模型,表示为java。util。具有可预测迭代顺序的语句集。
用于处理模型对象的其他实用程序功能在组织中提供。openrdf。模型util。模型实用类。

代码示例

代码示例来源:origin: org.openrdf.sesame/sesame-rio-testsuite

private final Model getTestModel(String datatypeValue, IRI datatypeURI) {
  Model result = new LinkedHashModel();
  result.add(vf.createStatement(vf.createBNode(), DC.DESCRIPTION,
      vf.createLiteral(datatypeValue, datatypeURI)));
  return result;
}

代码示例来源:origin: org.openrdf.sesame/sesame-store

private Binding getBinding(Resource bindingNode) {
    Literal name = (Literal)model.filter(bindingNode, VARIABLE, null).objects().iterator().next();
    Value value = model.filter(bindingNode, VALUE, null).objects().iterator().next();
    return new BindingImpl(name.getLabel(), value);
  }
}

代码示例来源:origin: eu.optique-project/r2rml-api-sesame-bridge

@Override
public Collection<Object> getSubjects(Object graph, Object pred, Object obj) {
  Model m = ((Model) graph).filter(null, (URI) pred, (Value) obj,
      (Resource) null);
  Collection<Object> c = new HashSet<Object>();
  c.addAll(m.subjects());
  return c;
}

代码示例来源:origin: stackoverflow.com

Model model = ...
 model.addLiteral (subject, predicate, 10);
 model.addLiteral (subject, predicate, 0.5);
 model.addLiteral (subject, predicate, (float)0.5);
 model.addLiteral (subject, predicate, ResourceFactory.createTypedLiteral(20));
 model.addLiteral (subject, predicate, ResourceFactory.createTypedLiteral(0.99));
 model.addLiteral (subject, predicate, true);
 model.add (subject, predicate, ResourceFactory.createTypedLiteral("2012-03-11", XSDDatatype.XSDdate));
 model.add (subject, predicate, ResourceFactory.createTypedLiteral("P2Y", XSDDatatype.XSDduration));

代码示例来源:origin: it.unibz.inf.ontop/ontop-obdalib-r2rml

/**
 * method to find the triplesmap node referenced in a parent join condition
 * 
 * @param myModel
 *            - the Model of mappings
 * @param predobjNode
 *            - the pred obj node containing the join condition
 * @return the Resource node refferred to in the condition
 */
public Resource getReferencedTripleMap(Model myModel, Resource predobjNode) {
  // process OBJECTMAP
  Model m = myModel.filter(predobjNode, R2RMLVocabulary.objectMap, null);
  if (!m.isEmpty()) {
    Resource object = m.objectResource();
    // look for parentTriplesMap declaration
    m = myModel.filter(object, R2RMLVocabulary.parentTriplesMap, null);
    if (!m.isEmpty()) {
      return m.objectResource();
    }
  }
  return null;
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-testsuite

@Test
public void testEndOfLineEmptyCommentWithSpaceBoth()
  throws Exception
{
  RDFParser ntriplesParser = createRDFParser();
  Model model = new LinkedHashModel();
  ntriplesParser.setRDFHandler(new StatementCollector(model));
  ntriplesParser.parse(new StringReader(
      "<urn:test:subject> <urn:test:predicate> <urn:test:object> . # \n"), "http://example/");
  assertEquals(1, model.size());
  assertEquals("urn:test:object", model.objectString().get());
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-testsuite

@Test
public void testEscapes()
  throws Exception
{
  RDFParser ntriplesParser = createRDFParser();
  Model model = new LinkedHashModel();
  ntriplesParser.setRDFHandler(new StatementCollector(model));
  ntriplesParser.parse(new StringReader(
      "<urn:test:subject> <urn:test:predicate> \" \\t \\b \\n \\r \\f \\\" \\' \\\\ \" . "),
      "http://example/");
  assertEquals(1, model.size());
  assertEquals(" \t \b \n \r \f \" \' \\ ", model.objectLiteral().get().getLabel());
}

代码示例来源:origin: org.openrdf.sesame/sesame-repository-sail

@Override
  public void parse(Model model, Resource implNode)
    throws RepositoryConfigException
  {
    super.parse(model, implNode);

    try {
      Models.objectLiteral(model.filter(implNode, ProxyRepositorySchema.PROXIED_ID, null)).ifPresent(
          lit -> setProxiedRepositoryID(lit.getLabel()));
    }
    catch (ModelException e) {
      throw new RepositoryConfigException(e.getMessage(), e);
    }
  }
}

代码示例来源:origin: blazegraph/database

@Test
public void testDescribeAWhere()
  throws Exception
{
  loadTestData("/testdata-query/dataset-describe.trig");
  StringBuilder query = new StringBuilder();
  query.append(getNamespaceDeclarations());
  query.append("DESCRIBE ?x WHERE {?x rdfs:label \"a\". } ");
  GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());
  ValueFactory f = conn.getValueFactory();
  URI a = f.createURI("http://example.org/a");
  URI p = f.createURI("http://example.org/p");
  Model result = QueryResults.asModel(gq.evaluate());
  Set<Value> objects = result.filter(a, p, null).objects();
  assertNotNull(objects);
  for (Value object : objects) {
    if (object instanceof BNode) {
      assertTrue(result.contains((Resource)object, null, null));
      assertEquals(2, result.filter((Resource)object, null, null).size());
    }
  }
}

代码示例来源:origin: org.openrdf.alibaba/alibaba-model

private void writeObject(ObjectOutputStream s) throws IOException {
  // Write out any hidden serialization magic
  s.defaultWriteObject();
  // Write in size
  Model delegate = getDelegate();
  s.writeInt(delegate.size());
  // Write in all elements
  for (Statement st : delegate) {
    Resource subj = st.getSubject();
    URI pred = st.getPredicate();
    Value obj = st.getObject();
    Resource ctx = st.getContext();
    s.writeObject(new ContextStatementImpl(subj, pred, obj, ctx));
  }
}

代码示例来源:origin: org.apache.marmotta/ldclient-provider-mediawiki

private static void addTriple(Resource subject, String predicate, String object, Model model, ValueFactory valueFactory)
    throws RepositoryException {
  if (predicate == null || object == null) return;
  final URI predUri = valueFactory.createURI(predicate);
  final URI objUri = valueFactory.createURI(object);
  Statement stmt = valueFactory.createStatement(subject, predUri, objUri);
  model.add(stmt);
}

代码示例来源:origin: org.openrdf.sesame/sesame-sail-inferencer

private int applyRuleRdfs4a()
  throws SailException
{
  int nofInferred = 0;
  Model iter = newThisIteration.filter(null, null, null);
  for(Statement st : iter) {
    boolean added = addInferredStatement(st.getSubject(), RDF.TYPE, RDFS.RESOURCE);
    if (added) {
      nofInferred++;
    }
  }
  return nofInferred;
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-testsuite

@Test
public void testBlankNodeIdentifiersRDF11()
  throws Exception
{
  RDFParser ntriplesParser = createRDFParser();
  Model model = new LinkedHashModel();
  ntriplesParser.setRDFHandler(new StatementCollector(model));
  ntriplesParser.parse(new StringReader("_:123 <urn:test:predicate> _:456 ."), "http://example/");
  assertEquals(1, model.size());
}

代码示例来源:origin: blazegraph/database

@Test
public void testDescribeB()
  throws Exception
{
  loadTestData("/testdata-query/dataset-describe.trig");
  StringBuilder query = new StringBuilder();
  query.append(getNamespaceDeclarations());
  query.append("DESCRIBE ex:b");
  GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());
  ValueFactory f = conn.getValueFactory();
  URI b = f.createURI("http://example.org/b");
  URI p = f.createURI("http://example.org/p");
  Model result = QueryResults.asModel(gq.evaluate());
  Set<Resource> subjects = result.filter(null, p, b).subjects();
  assertNotNull(subjects);
  for (Value subject : subjects) {
    if (subject instanceof BNode) {
      assertTrue(result.contains(null, null, subject));
    }
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-sail-inferencer

private void addQueryNode(Model m, Resource implNode, IRI predicate, String queryText) {
    if (null != queryText) {
      ValueFactory factory = SimpleValueFactory.getInstance();
      BNode queryNode = factory.createBNode();
      m.add(implNode, predicate, queryNode);
      m.add(queryNode, RDF.TYPE, SP.CONSTRUCT_CLASS);
      m.add(queryNode, SP.TEXT_PROPERTY, factory.createLiteral(queryText));
    }
  }
}

代码示例来源:origin: anno4j/anno4j

private void checkPropertyRanges() {
  loop: for (Statement st : ds.match(null, RDF.TYPE, RDF.PROPERTY)) {
    Resource p = st.getSubject();
    if (!ds.contains(p, RDFS.RANGE, null)) {
      for (Value sup : ds.match(p, RDFS.SUBPROPERTYOF, null).objects()) {
        for (Value obj : ds.match(sup, RDFS.RANGE, null).objects()) {
          ds.add(p, RDFS.RANGE, obj);
          continue loop;
        }
      }
      ds.add(p, RDFS.RANGE, RDFS.RESOURCE);
    }
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-sail-lucene-api

@Override
public Resource export(Model m) {
  Resource implNode = super.export(m);
  ValueFactory vf = SimpleValueFactory.getInstance();
  if (indexDir != null) {
    m.add(implNode, INDEX_DIR, SimpleValueFactory.getInstance().createLiteral(indexDir));
  }
  for (String key : getParameterNames()) {
    m.add(implNode, vf.createIRI(LuceneSailConfigSchema.NAMESPACE, key),
        vf.createLiteral(getParameter(key)));
  }
  return implNode;
}

代码示例来源:origin: org.openrdf.sesame/sesame-sparql-testsuite

@Test
public void testSES2104ConstructBGPSameURI()
  throws Exception
{
  final String queryStr = "PREFIX : <urn:> CONSTRUCT {:x :p :x } WHERE {} ";
  conn.add(new StringReader("@prefix : <urn:> . :a :p :b . "), "", RDFFormat.TURTLE);
  final IRI x = conn.getValueFactory().createIRI("urn:x");
  final IRI p = conn.getValueFactory().createIRI("urn:p");
  GraphQuery query = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryStr);
  Model result = QueryResults.asModel(query.evaluate());
  assertNotNull(result);
  assertFalse(result.isEmpty());
  assertTrue(result.contains(x, p, x));
}

代码示例来源:origin: org.openrdf.sesame/sesame-sail-inferencer

private int applyRuleRdfs4b()
  throws SailException
{
  int nofInferred = 0;
  Model iter = newThisIteration.filter(null, null, null);
  for(Statement st : iter) {
    Value uuu = st.getObject();
    if (uuu instanceof Resource) {
      boolean added = addInferredStatement((Resource)uuu, RDF.TYPE, RDFS.RESOURCE);
      if (added) {
        nofInferred++;
      }
    }
  }
  return nofInferred;
}

代码示例来源:origin: org.openrdf.sesame/sesame-sparql-testsuite

@Test
public void testDescribeA()
  throws Exception
{
  loadTestData("/testdata-query/dataset-describe.trig");
  StringBuilder query = new StringBuilder();
  query.append(getNamespaceDeclarations());
  query.append("DESCRIBE ex:a");
  GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());
  ValueFactory f = conn.getValueFactory();
  IRI a = f.createIRI("http://example.org/a");
  IRI p = f.createIRI("http://example.org/p");
  Model result = QueryResults.asModel(gq.evaluate());
  Set<Value> objects = result.filter(a, p, null).objects();
  assertNotNull(objects);
  for (Value object : objects) {
    if (object instanceof BNode) {
      assertTrue(result.contains((Resource)object, null, null));
      assertEquals(2, result.filter((Resource)object, null, null).size());
    }
  }
}

相关文章