org.apache.jena.rdf.model.NodeIterator Java Examples

The following examples show how to use org.apache.jena.rdf.model.NodeIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelContainer.java    From hypergraphql with Apache License 2.0 6 votes vote down vote up
String getValueOfDataProperty(RDFNode subject, String predicateURI, Map<String, Object> args) {

        final NodeIterator iterator = this.model.listObjectsOfProperty(subject.asResource(), getPropertyFromUri(predicateURI));
        while (iterator.hasNext()) {

            final RDFNode data = iterator.next();
            if (data.isLiteral()) {

                if (args.containsKey("lang")
                        && args.get("lang").toString().equalsIgnoreCase(data.asLiteral().getLanguage())) {
                    return data.asLiteral().getString();
                } else {
                    return data.asLiteral().getString();
                }
            }
        }
        return null;
    }
 
Example #2
Source File: ModelContainer.java    From hypergraphql with Apache License 2.0 6 votes vote down vote up
List<String> getValuesOfDataProperty(RDFNode subject, String predicateURI, Map<String, Object> args) {

        final List<String> valList = new ArrayList<>();

        final NodeIterator iterator = model.listObjectsOfProperty(subject.asResource(), getPropertyFromUri(predicateURI));

        while (iterator.hasNext()) {

            RDFNode data = iterator.next();

            if (data.isLiteral()) {
                if (!args.containsKey("lang") || args.get("lang").toString().equalsIgnoreCase(data.asLiteral().getLanguage())) {
                        valList.add(data.asLiteral().getString());
                }
            }
        }
        return valList;
    }
 
Example #3
Source File: ModelContainer.java    From hypergraphql with Apache License 2.0 6 votes vote down vote up
List<String> getValuesOfDataProperty(RDFNode subject, String predicateURI, Map<String, Object> args) {

        List<String> valList = new ArrayList<>();

        NodeIterator iterator = this.model.listObjectsOfProperty(subject.asResource(), getPropertyFromUri(predicateURI));

        while (iterator.hasNext()) {

            RDFNode data = iterator.next();

            if (data.isLiteral()) {
                if (args.containsKey("lang")) {
                    if (data.asLiteral().getLanguage().equals(args.get("lang").toString())) {
                        valList.add(data.asLiteral().getString());
                    }
                } else {
                    valList.add(data.asLiteral().getString());
                }
            }
        }
        return valList;
    }
 
Example #4
Source File: RDFToTopicMapConverter.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * Finds all RTM_IN_SCOPE properties for this property and returns a
 * collection containing the RDF URIs of the values as URILocators.
 */
private Collection getScope(RDFNode rdfprop, Model model)
  throws JenaException, MalformedURLException {

  Resource subject = (Resource) rdfprop;
  Property prop = model.getProperty(RTM_IN_SCOPE);
  NodeIterator it = model.listObjectsOfProperty(subject, prop);
  ArrayList scope = new ArrayList();

  while (it.hasNext()) {
    Object o = it.next();

    if (!(o instanceof Resource))
      throw new RDFMappingException("Scoping topic must be specified by a resource, not by " + o);

    Resource obj = (Resource) o;
    LocatorIF loc = new URILocator(obj.getURI());
    scope.add(loc);
  }

  return scope;
}
 
Example #5
Source File: RDFToTopicMapConverter.java    From ontopia with Apache License 2.0 6 votes vote down vote up
private TopicIF getType(RDFNode rdfprop, Model model)
  throws JenaException, MalformedURLException {

  Resource subject = (Resource) rdfprop;
  Property prop = model.getProperty(RTM_TYPE);
  NodeIterator it = model.listObjectsOfProperty(subject, prop);
  while (it.hasNext()) {
    Resource obj = (Resource) it.next();
    LocatorIF loc = new URILocator(obj.getURI());
    TopicIF topic = topicmap.getTopicBySubjectIdentifier(loc);
    if (topic == null) {
      topic = builder.makeTopic();
      topic.addSubjectIdentifier(loc);
    }
    return topic;
  }
  return null;
}
 
Example #6
Source File: Service.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
private Set<String> findIdentifiers(Model model, Set<String> input, LinkedList<QueryNode> path) {

        Set<String> subjects;
        Set<String> objects;
        if (input == null) {
            objects = new HashSet<>();
        } else {
            objects = input;
        }

        // NB: This hasn't been converted to use the NIO streaming API as it uses reentrant recursion
        for (QueryNode queryNode : path) {
            subjects = new HashSet<>(objects);
            objects = new HashSet<>();
            if (!subjects.isEmpty()) {
                for (String subject : subjects) {
                    Resource subjectResource = model.createResource(subject);
                    NodeIterator partialObjects = model.listObjectsOfProperty(subjectResource, queryNode.getNode());
                    while (partialObjects.hasNext()) {
                        objects.add(partialObjects.next().toString());
                    }
                }

            } else {

                NodeIterator objectsIterator = model.listObjectsOfProperty(queryNode.getNode());
                while (objectsIterator.hasNext()) {
                    objects.add(objectsIterator.next().toString());
                }
            }
        }
        return objects;
    }
 
Example #7
Source File: ModelContainer.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
List<RDFNode> getValuesOfObjectProperty(RDFNode subject, String predicateURI, String targetURI) {

        NodeIterator iterator = this.model.listObjectsOfProperty(subject.asResource(), getPropertyFromUri(predicateURI));
        List<RDFNode> rdfNodes = new ArrayList<>();
        iterator.forEachRemaining(node -> {
            if (!node.isLiteral()) {
                if(targetURI == null) {
                    rdfNodes.add(node);
                } else if(this.model.contains(node.asResource(), getPropertyFromUri(HGQLVocabulary.RDF_TYPE), getResourceFromUri(targetURI))) {
                    rdfNodes.add(node);
                }
            }
        });
        return rdfNodes;
    }
 
Example #8
Source File: ModelContainer.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
RDFNode getValueOfObjectProperty(RDFNode subject, String predicateURI, String targetURI) {
    NodeIterator iterator = this.model.listObjectsOfProperty(subject.asResource(), getPropertyFromUri(predicateURI));

    while (iterator.hasNext()) {
        RDFNode next = iterator.next();
        if (!next.isLiteral()) {
            if (targetURI != null && this.model.contains(next.asResource(), getPropertyFromUri(HGQLVocabulary.RDF_TYPE), getResourceFromUri(targetURI))) {
                return next;
            }
        }
    }
    return null;
}
 
Example #9
Source File: Service.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
protected Set<String> findIdentifiers(Model model, Set<String> input, LinkedList<QueryNode> path) {

        Set<String> subjects;
        Set<String> objects;
        if (input == null) {
            objects = new HashSet<>();
        } else {
            objects = input;
        }

        // NB: This hasn't been converted to use the NIO streaming API as it uses reentrant recursion
        for (QueryNode queryNode : path) {
            subjects = new HashSet<>(objects);
            objects = new HashSet<>();
            if (!subjects.isEmpty()) {
                for (String subject : subjects) {
                    Resource subjectResource = model.createResource(subject);
                    NodeIterator partialObjects = model.listObjectsOfProperty(subjectResource, queryNode.getNode());
                    while (partialObjects.hasNext()) {
                        objects.add(partialObjects.next().toString());
                    }
                }

            } else {

                NodeIterator objectsIterator = model.listObjectsOfProperty(queryNode.getNode());
                while (objectsIterator.hasNext()) {
                    objects.add(objectsIterator.next().toString());
                }
            }
        }
        return objects;
    }
 
Example #10
Source File: ModelContainer.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
List<RDFNode> getValuesOfObjectProperty(RDFNode subject, String predicateURI, String targetURI) {

        NodeIterator iterator = this.model.listObjectsOfProperty(subject.asResource(), getPropertyFromUri(predicateURI));
        List<RDFNode> rdfNodes = new ArrayList<>();
        iterator.forEachRemaining(node -> {
            if (!node.isLiteral()) {
                if(targetURI == null) {
                    rdfNodes.add(node);
                } else if(this.model.contains(node.asResource(), getPropertyFromUri(HGQLVocabulary.RDF_TYPE), getResourceFromUri(targetURI))) {
                    rdfNodes.add(node);
                }
            }
        });
        return rdfNodes;
    }
 
Example #11
Source File: ModelContainer.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
RDFNode getValueOfObjectProperty(RDFNode subject, String predicateURI, String targetURI) {

        NodeIterator iterator = this.model.listObjectsOfProperty(subject.asResource(), getPropertyFromUri(predicateURI));
        while (iterator.hasNext()) {

            RDFNode next = iterator.next();
            if (!next.isLiteral()) {
                if (targetURI != null && this.model.contains(next.asResource(), getPropertyFromUri(HGQLVocabulary.RDF_TYPE), getResourceFromUri(targetURI))) {
                    return next;
                }
            }
        }
        return null;
    }
 
Example #12
Source File: Exporter.java    From fcrepo-import-export with Apache License 2.0 5 votes vote down vote up
private void exportMembers(final Model model, final Set<URI> inboundMembers) {
    for (final String p : config.getPredicates()) {
        final NodeIterator members = model.listObjectsOfProperty(createProperty(p));
        while (members.hasNext()) {
            export(URI.create(members.nextNode().toString()));
        }
    }

    if (inboundMembers != null) {
        for (final URI inbound : inboundMembers) {
            export(inbound);
        }
    }
}
 
Example #13
Source File: JenaUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a Set of all superclasses (rdfs:subClassOf) of a given Resource. 
 * @param subClass  the subClass Resource
 * @return a Collection of class resources
 */
public static Collection<Resource> getSuperClasses(Resource subClass) {
	NodeIterator it = subClass.getModel().listObjectsOfProperty(subClass, RDFS.subClassOf);
	Set<Resource> results = new HashSet<>();
	while (it.hasNext()) {
		RDFNode node = it.nextNode();
		if (node instanceof Resource) {
			results.add((Resource)node);
		}
	}
	return results;
}
 
Example #14
Source File: RDFToTopicMapConverter.java    From ontopia with Apache License 2.0 5 votes vote down vote up
private LocatorIF getTopicIndicator(Resource subject, String property,
                                    Model model)
  throws JenaException, MalformedURLException {
  Property prop = model.getProperty(property);
  NodeIterator it = model.listObjectsOfProperty(subject, prop);
  while (it.hasNext()) {
    Resource obj = (Resource) it.next();
    if (obj.isAnon())
      continue; // FIXME: is this really ok?
    return new URILocator(obj.getURI());
  }
  return null;
}