org.apache.jena.rdf.model.ResIterator.nextResource()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(82)

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

ResIterator.nextResource介绍

暂无

代码示例

代码示例来源:origin: google/data-transfer-project

private List<VCard> parseAddressBook(Resource selfResource, SolidUtilities utilities)
  throws IOException {
 String peopleUri = selfResource.getProperty(NAME_EMAIL_INDEX_PROPERTY).getResource().getURI();
 Model peopleModel = utilities.getModel(peopleUri);
 List<VCard> vcards = new ArrayList<>();
 ResIterator subjects = peopleModel.listSubjects();
 while (subjects.hasNext()) {
  Resource subject = subjects.nextResource();
  Model personModel = utilities.getModel(subject.getURI());
  Resource personResource = SolidUtilities.getResource(subject.getURI(), personModel);
  if (personResource == null) {
   throw new IllegalStateException(subject.getURI() + " not found in " + subject.toString());
  }
  vcards.add(parsePerson(personResource));
 }
 return vcards;
}

代码示例来源:origin: com.powsybl/powsybl-triple-store-impl-jena

private static Resource[] subjectsTypes(Model model) {
  Set<Resource> types = new HashSet<>();
  ResIterator rs = model.listSubjects();
  while (rs.hasNext()) {
    Resource r = rs.nextResource();
    Statement s = type(r);
    if (s != null) {
      types.add(s.getObject().asResource());
    }
  }
  return types.toArray(new Resource[0]);
}

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

protected void writeRDFStatements( Model model, PrintWriter writer )
  {
  ResIterator rIter = model.listSubjects();
  while (rIter.hasNext()) writeRDFStatements( model, rIter.nextResource(), writer );
  }

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

protected void writeRDFStatements( Model model, PrintWriter writer )
  {
  ResIterator rIter = model.listSubjects();
  while (rIter.hasNext()) writeRDFStatements( model, rIter.nextResource(), writer );
  }

代码示例来源:origin: vivo-project/Vitro

private List<Resource> getPortal1s(Model model) {
  List<Resource> portals = new ArrayList<Resource>();
  try {
    model.enterCriticalSection(Lock.READ);
    ResIterator portalIt = model.listResourcesWithProperty(
        RDF.type, PORTAL);
    while (portalIt.hasNext()) {
      Resource portal = portalIt.nextResource();
      if ("portal1".equals(portal.getLocalName())) {
        portals.add(portal);
      }
    }
  } finally {
    model.leaveCriticalSection();
  }
  return portals;
}

代码示例来源:origin: semantic-integration/hypergraphql

private Set<String> findRootIdentifiers(Model model, TypeConfig targetName) {
  Set<String> identifiers = new HashSet<>();
  Model currentmodel = ModelFactory.createDefaultModel();
  Resource res = currentmodel.createResource(targetName.getId());
  Property property = currentmodel.createProperty(RDF_TYPE);
  ResIterator iterator = model.listResourcesWithProperty(property, res);
  while (iterator.hasNext()) {
    identifiers.add(iterator.nextResource().toString());
  }
  return identifiers;
}

代码示例来源:origin: semantic-integration/hypergraphql

private Set<String> findRootIdentifiers(Model model, TypeConfig targetName) {
  Set<String> identifiers = new HashSet<>();
  Model currentmodel = ModelFactory.createDefaultModel();
  Resource res = currentmodel.createResource(targetName.getId());
  Property property = currentmodel.createProperty(RDF_TYPE);
  ResIterator iterator = model.listResourcesWithProperty(property, res);
  while (iterator.hasNext()) {
    identifiers.add(iterator.nextResource().toString());
  }
  return identifiers;
}

代码示例来源:origin: at.researchstudio.sat/won-matcher-service

/**
 * Get the won node URI from a {@link Dataset}
 *
 * @param ds Dataset which holds won node information
 * @return
 */
private String getWonNodeUriFromDataset(Dataset ds) {
 if (ds.listNames().hasNext()) {
  Model model = ds.getNamedModel(ds.listNames().next());
  if (model.listSubjectsWithProperty(WON.HAS_URI_PATTERN_SPECIFICATION).hasNext()) {
   return model.listSubjectsWithProperty(WON.HAS_URI_PATTERN_SPECIFICATION).nextResource().toString();
  }
 }
 return null;
}

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

private void processModel(Model baseModel) throws IOException
{
  writeLine("{");
  boolean first = true;
  ResIterator subjectIterator = baseModel.listSubjects();
  while (subjectIterator.hasNext()) {
    if (!first) {
      writeLine(",");
    }
    first = false;
    Resource subjectResource = subjectIterator.nextResource();
    processSubject(subjectResource);
  }
  writeLine("");
  writeLine("}");
}

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

/**
 * Test that a transitive reduction is complete.
 * Assumes test graph has no cycles (other than the trivial
 * identity ones). 
 */
public void doTestTransitiveReduction(Model model, Property dp) {
  InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model);
  
  for (ResIterator i = im.listSubjects(); i.hasNext();) {
    Resource base = i.nextResource();
    
    List<RDFNode> directLinks = new ArrayList<>();
    for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) {
      directLinks.add(j.next());
    }
    for (int n = 0; n < directLinks.size(); n++) {
      Resource d1 = (Resource)directLinks.get(n);
      for (int m = n+1; m < directLinks.size(); m++) {
        Resource d2 = (Resource)directLinks.get(m);
        
        if (im.contains(d1, dp, d2) && ! base.equals(d1) && !base.equals(d2)) {
          assertTrue("Triangle discovered in transitive reduction", false);
        }
      }
    }
  }
}

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

/**
 * Test that a transitive reduction is complete.
 * Assumes test graph has no cycles (other than the trivial
 * identity ones). 
 */
public void doTestTransitiveReduction(Model model, Property dp) {
  InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model);
  
  for (ResIterator i = im.listSubjects(); i.hasNext();) {
    Resource base = i.nextResource();
    
    List<RDFNode> directLinks = new ArrayList<>();
    for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) {
      directLinks.add(j.next());
    }
    for (int n = 0; n < directLinks.size(); n++) {
      Resource d1 = (Resource)directLinks.get(n);
      for (int m = n+1; m < directLinks.size(); m++) {
        Resource d2 = (Resource)directLinks.get(m);
        
        if (im.contains(d1, dp, d2) && ! base.equals(d1) && !base.equals(d2)) {
          assertTrue("Triangle discovered in transitive reduction", false);
        }
      }
    }
  }
}

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

protected void writeModel(Model model)
{
  // Needed only for no prefixes, no blank first line. 
  boolean doingFirst = true;
  ResIterator rIter = listSubjects(model);
  for (; rIter.hasNext();)
  {
    // Subject:
    // First - it is something we will write out as a structure in an object field?
    // That is, a RDF list or the object of exactly one statement.
    Resource subject = rIter.nextResource();
    if ( skipThisSubject(subject) )
    {
      if (N3JenaWriter.DEBUG)
        out.println("# Skipping: " + formatResource(subject));
      continue;
    }
    // We really are going to print something via writeTriples
    if (doingFirst)
      doingFirst = false;
    else
      out.println();
    writeOneGraphNode(subject) ;
    
    
  }
  rIter.close();
}

代码示例来源:origin: HuygensING/timbuctoo

public RmlMappingDocument fromRdf(Model data, Function<RdfResource, Optional<DataSource>> dataSourceFactory) {
 ResIterator tripleMaps = data.listSubjectsWithProperty(data.createProperty(NS_RR + "subjectMap"));
 MappingDocumentBuilder resultBuilder = rmlMappingDocument();
 try {
  while (tripleMaps.hasNext()) {
   Resource resource = tripleMaps.nextResource();
   buildTripleMap(JenaResource.fromModel(data, resource), resultBuilder.withTripleMap(resource.getURI()));
  }
 } finally {
  tripleMaps.close();
 }
 return resultBuilder.build(dataSourceFactory);
}

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

/**
 * Run all the tests in the manifest
 * @param manifestFile the name of the manifest file relative to baseDir
 * @param log set to true to enable derivation logging
 * @param stats set to true to log performance statistics
 * @return true if all the tests pass
 * @throws IOException if one of the test files can't be found
 */
public boolean runTests(String manifestFile, boolean log, boolean stats) throws IOException {
  // Load up the manifest
  Model manifest = FileManager.get().loadModel(baseDir + manifestFile);
  ResIterator tests = manifest.listResourcesWithProperty(RDF.type, PositiveEntailmentTest);
  while (tests.hasNext()) {
    Resource test = tests.nextResource();
    if (!runTest(test, log, stats)) return false;
  }
  tests = manifest.listResourcesWithProperty(RDF.type, NegativeEntailmentTest);
  while (tests.hasNext()) {
    Resource test = tests.nextResource();
    if (!runTest(test, log, stats)) return false;
  }
  return true;
}

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

private void processIterator( final ResIterator rIter, final boolean[] subjf )
{
  for (int i = 0; i < num; i++)
  {
    subjf[i] = false;
  }
  while (rIter.hasNext())
  {
    final Resource subj = rIter.nextResource();
    Boolean found = false;
    for (int i = 0; i < num; i++)
    {
      if (subj.equals(subject[i]))
      {
        found = true;
        Assert.assertFalse("Should not have found " + subject[i]
            + " already", subjf[i]);
        subjf[i] = true;
      }
    }
    Assert.assertTrue("Should have found " + subj, found);
  }
}

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

protected void writeModel(Model model)
{
  // Needed only for no prefixes, no blank first line. 
  boolean doingFirst = true;
  ResIterator rIter = listSubjects(model);
  for (; rIter.hasNext();)
  {
    // Subject:
    // First - it is something we will write out as a structure in an object field?
    // That is, a RDF list or the object of exactly one statement.
    Resource subject = rIter.nextResource();
    if ( skipThisSubject(subject) )
    {
      if (N3JenaWriter.DEBUG)
        out.println("# Skipping: " + formatResource(subject));
      continue;
    }
    // We really are going to print something via writeTriples
    if (doingFirst)
      doingFirst = false;
    else
      out.println();
    writeOneGraphNode(subject) ;
    
    
  }
  rIter.close();
}

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

private void processIterator( final ResIterator rIter, final boolean[] subjf )
{
  for (int i = 0; i < num; i++)
  {
    subjf[i] = false;
  }
  while (rIter.hasNext())
  {
    final Resource subj = rIter.nextResource();
    Boolean found = false;
    for (int i = 0; i < num; i++)
    {
      if (subj.equals(subject[i]))
      {
        found = true;
        Assert.assertFalse("Should not have found " + subject[i]
            + " already", subjf[i]);
        subjf[i] = true;
      }
    }
    Assert.assertTrue("Should have found " + subj, found);
  }
}

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

/**
 * Run all the tests in the manifest
 * @param manifestFile the name of the manifest file relative to baseDir
 * @param log set to true to enable derivation logging
 * @param stats set to true to log performance statistics
 * @return true if all the tests pass
 * @throws IOException if one of the test files can't be found
 */
public boolean runTests(String manifestFile, boolean log, boolean stats) throws IOException {
  // Load up the manifest
  Model manifest = FileManager.get().loadModel(baseDir + manifestFile);
  ResIterator tests = manifest.listResourcesWithProperty(RDF.type, PositiveEntailmentTest);
  while (tests.hasNext()) {
    Resource test = tests.nextResource();
    if (!runTest(test, log, stats)) return false;
  }
  tests = manifest.listResourcesWithProperty(RDF.type, NegativeEntailmentTest);
  while (tests.hasNext()) {
    Resource test = tests.nextResource();
    if (!runTest(test, log, stats)) return false;
  }
  return true;
}

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

/**
   * Report of functor literals leaking out of inference graphs and raising CCE
   * in iterators.
   */
  public void testFunctorCCE() {
    Model base = ModelFactory.createDefaultModel();
    base.read("file:testing/reasoners/bugs/cceTest.owl");
    InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base);

//        boolean b =
      anyInstancesOfNothing(test);
    ResIterator rIter = test.listSubjects();
    while (rIter.hasNext()) {
//            Resource res =
        rIter.nextResource();
    }
  }

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

/**
   * Report of functor literals leaking out of inference graphs and raising CCE
   * in iterators.
   */
  public void testFunctorCCE() {
    Model base = ModelFactory.createDefaultModel();
    base.read("file:testing/reasoners/bugs/cceTest.owl");
    InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base);

//        boolean b =
      anyInstancesOfNothing(test);
    ResIterator rIter = test.listSubjects();
    while (rIter.hasNext()) {
//            Resource res =
        rIter.nextResource();
    }
  }

相关文章