org.apache.jena.ontology.Individual Java Examples

The following examples show how to use org.apache.jena.ontology.Individual. 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: AbstractRdfDocumentGraphConsumer.java    From baleen with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private Individual addIndividual(OntModel model, Vertex v, String className) {
  OntClass ontClass = model.getOntClass(namespace + className);
  if (ontClass != null) {
    Individual individual = ontClass.createIndividual(namespace + v.id());
    Map<String, List> propertyValueMap = ElementHelper.vertexPropertyValueMap(v);
    propertyValueMap
        .entrySet()
        .forEach(
            e -> {
              Property property = model.getProperty(namespace + e.getKey());
              if (property != null) {
                e.getValue().forEach(value -> individual.addProperty(property, value.toString()));
              }
            });
    return individual;
  } else {
    getMonitor().warn("Missing ontology class {}", className);
  }
  return null;
}
 
Example #2
Source File: AbstractRdfEntityGraphConsumer.java    From baleen with Apache License 2.0 6 votes vote down vote up
private ObjectProperty addRelationToModel(OntModel model, Edge e) {
  Individual source = model.getIndividual(namespace + e.outVertex().id());
  Individual target = model.getIndividual(namespace + e.inVertex().id());
  ObjectProperty property = model.getObjectProperty(namespace + e.label());

  if (source != null && target != null && property != null) {
    source.addProperty(property, target);
    return property;
  } else {
    getMonitor()
        .warn(
            "Missing individuals {} or {} or relation {}",
            e.outVertex(),
            e.inVertex(),
            e.label());
    return null;
  }
}
 
Example #3
Source File: AbstractRdfEntityGraphConsumer.java    From baleen with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private Individual addIndividual(OntModel model, Vertex v, String className) {
  OntClass ontClass = model.getOntClass(namespace + className);
  if (ontClass != null) {
    Individual individual = ontClass.createIndividual(namespace + v.id());
    Map<String, List> propertyValueMap = ElementHelper.vertexPropertyValueMap(v);
    propertyValueMap
        .entrySet()
        .forEach(
            e -> {
              Property property = model.getProperty(namespace + e.getKey());
              if (property != null) {
                e.getValue().forEach(value -> individual.addProperty(property, value.toString()));
              }
            });
    return individual;
  } else {
    getMonitor().warn("Missing ontology class {}", className);
  }
  return null;
}
 
Example #4
Source File: ModelStorage.java    From FCA-Map with GNU General Public License v3.0 5 votes vote down vote up
private void acquireIndividuals() {
  for (ExtendedIterator<Individual> it = ontModel.listIndividuals(); it.hasNext(); ) {
    Individual i = it.next();
    if (isIgnoredIndividual(i)) continue;
    individuals.add(i);
  }
}
 
Example #5
Source File: OntModelWrapper.java    From FCA-Map with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Acquire the instances and skip the ignored one
 */
private void acquireInstances() {
  for (ExtendedIterator<Individual> it = m_ontology.listIndividuals(); it.hasNext(); ) {
    Individual i = it.next();
    if (isSkipInstance(i)) continue;
    m_instances.add(i);
  }
}
 
Example #6
Source File: RDFToManifest.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private Individual findRO(OntModel model, URI base) {
	try (ClosableIterable<? extends OntResource> instances = iterate(ore.Aggregation
			.listInstances())) {
		for (OntResource o : instances)
			// System.out.println("Woo " + o);
			return o.asIndividual();
	}
	// Fallback - resolve as "/"
	// TODO: Ensure it's an Aggregation?
	return model.getIndividual(base.toString());
}
 
Example #7
Source File: RDFToManifest.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private List<Agent> getAgents(URI base, Individual in,
		ObjectProperty property) {
	List<Agent> creators = new ArrayList<>();
	for (Individual agent : listObjectProperties(in, property)) {
		Agent a = new Agent();

		// Check for any ORCIDs, note that "orcid" is mapped as
		// prov:alternateOf in our modified bundle.jsonld
		for (Individual alternate : listObjectProperties(agent, prov.alternateOf)) {
			if (alternate.isURIResource() && (
					alternate.getURI().startsWith("https://orcid.org/") ||
					alternate.getURI().startsWith("http://orcid.org/"))) {
				// TODO: Check against https://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
				a.setOrcid(URI.create(alternate.getURI()));
				break;
			}
		}
		if (agent.isURIResource()) {
			URI agentURI = relativizeFromBase(agent.getURI(), base);
			if ("orcid.org".equals(agentURI.getHost()) && a.getOrcid() == null) {
				a.setOrcid(agentURI);
			} else {
				a.setUri(agentURI);
			}
		}

		RDFNode name = agent.getPropertyValue(foaf.name);
		if (name != null && name.isLiteral())
			a.setName(name.asLiteral().getLexicalForm());
		creators.add(a);
	}
	return creators;
}
 
Example #8
Source File: RDFToManifest.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private Set<Individual> listObjectProperties(OntResource ontResource,
		ObjectProperty prop) {
	LinkedHashSet<Individual> results = new LinkedHashSet<>();
	try (ClosableIterable<RDFNode> props = iterate(ontResource
			.listPropertyValues(prop))) {
		for (RDFNode node : props) {
			if (!node.isResource() || !node.canAs(Individual.class))
				continue;
			results.add(node.as(Individual.class));
		}
	}
	return results;
}
 
Example #9
Source File: ROEvoSerializer.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private void addRevision(OntModel model,
		Revision revision) {
	OntClass VersionableResource = model.createClass("http://purl.org/wf4ever/roevo#VersionableResource");
	VersionableResource.addSuperClass(prov.Entity);
	Individual revisionResource = model.createIndividual(revision.getIdentifier().toASCIIString(), 
			VersionableResource);
	revisionResource.addRDFType(prov.Entity);
}
 
Example #10
Source File: ROEvoSerializer.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private void addPrevious(OntModel model,
		Revision revision, Revision previous) {
	OntClass VersionableResource = model.createClass("http://purl.org/wf4ever/roevo#VersionableResource");
	VersionableResource.addSuperClass(prov.Entity);
	
	Individual revisionResource = model.createIndividual(revision.getIdentifier().toASCIIString(), 
			VersionableResource);
	Individual previousResource = model.createIndividual(previous.getIdentifier().toASCIIString(), 
			VersionableResource);
	revisionResource.addProperty(prov.wasRevisionOf, previousResource);
}
 
Example #11
Source File: AbstractRdfDocumentGraphConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
private ObjectProperty addRelationToModel(OntModel model, Edge e) {
  Individual source = model.getIndividual(namespace + e.outVertex().id());
  Individual target = model.getIndividual(namespace + e.inVertex().id());

  ObjectProperty property = model.getObjectProperty(namespace + e.label());
  source.addProperty(property, target);

  return property;
}
 
Example #12
Source File: ModelStorage.java    From FCA-Map with GNU General Public License v3.0 4 votes vote down vote up
public Set<Individual> getIndividuals() {
  return individuals;
}
 
Example #13
Source File: ModelStorage.java    From FCA-Map with GNU General Public License v3.0 4 votes vote down vote up
private static final boolean isIgnoredIndividual(Individual i) {
  return i.hasProperty(RDF.type, SKOS.Concept) || i.hasProperty(RDF.type, DBkWik.Image);
}
 
Example #14
Source File: OntModelWrapper.java    From FCA-Map with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Check whether the individual should be skipped
 *
 * @param i individual
 * @return true means the individual should be ignored
 */
private static final boolean isSkipInstance(Individual i) {
  return i.hasProperty(RDF.type, SKOS.Concept) ||
         i.hasProperty(RDF.type, DBkWik.Image);
}
 
Example #15
Source File: OntModelWrapper.java    From FCA-Map with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the hash set of instances
 *
 * @return m_instances
 */
public Set<Individual> getInstances() {
  return m_instances;
}