org.apache.jena.vocabulary.XSD Java Examples

The following examples show how to use org.apache.jena.vocabulary.XSD. 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: RDFNodeFactory.java    From Processor with Apache License 2.0 6 votes vote down vote up
public static final RDFNode createTyped(String value, Resource valueType)
   {
if (value == null) throw new IllegalArgumentException("Param value cannot be null");

       // without value type, return default xsd:string value
       if (valueType == null) return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring);

       // if value type is from XSD namespace, value is treated as typed literal with XSD datatype
       if (valueType.getNameSpace().equals(XSD.getURI()))
       {
           RDFDatatype dataType = NodeFactory.getType(valueType.getURI());
           return ResourceFactory.createTypedLiteral(value, dataType);
       }
       // otherwise, value is treated as URI resource
       else
           return ResourceFactory.createResource(value);
   }
 
Example #2
Source File: OwlSchemaFactory.java    From baleen with Apache License 2.0 6 votes vote down vote up
/** Creates an entity ontology */
public OntModel createEntityOntology() {
  OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);

  OntClass entity = addType(ontModel, null, getType(ENTITY));
  OntClass event = addType(ontModel, null, getType(EVENT));

  addProperty(ontModel, entity, "value", "The value of the mention", XSD.xstring);
  addProperty(ontModel, entity, "longestValue", "The longest value of the mention", XSD.xstring);
  addProperty(
      ontModel, entity, "mostCommonValue", "The most common value of the mention", XSD.xstring);
  addProperty(ontModel, entity, "mentions", "The details of the mentions", XSD.xstring);
  addProperty(ontModel, "docId", "The docId the mention came from", XSD.xstring);

  addRelation(ontModel, entity, entity, RELATION, "A relationship between two entities");
  addRelation(ontModel, entity, event, PARTICIPANT_IN, "A participant in the event");

  return ontModel;
}
 
Example #3
Source File: JenaUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the usual default namespaces for rdf, rdfs, owl and xsd.
 * @param prefixMapping  the Model to modify
 */
public static void initNamespaces(PrefixMapping prefixMapping) {
    ensurePrefix(prefixMapping, "rdf",  RDF.getURI());
    ensurePrefix(prefixMapping, "rdfs", RDFS.getURI());
    ensurePrefix(prefixMapping, "owl",  OWL.getURI());
    ensurePrefix(prefixMapping, "xsd",  XSD.getURI());
}
 
Example #4
Source File: OwlSchemaFactory.java    From baleen with Apache License 2.0 5 votes vote down vote up
/** Creates a document ontology */
public OntModel createDocumentOntology() {
  OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);

  OntClass document = addType(ontModel, null, getType(Document.class.getSimpleName()));
  OntClass mention = ontModel.createClass(namespace + MENTION);

  mention.addComment("Root mention type", EN);
  addProperty(ontModel, mention, "begin", "The start of the mention offset", XSD.xint);
  addProperty(ontModel, mention, "end", "The end of the mention offset", XSD.xint);
  addProperty(ontModel, mention, "value", "The value of the mention", XSD.xstring);
  addProperty(ontModel, mention, "docId", "The docId the mention came from", XSD.xstring);

  OntClass reference = addType(ontModel, null, getType(REFERENCE_TARGET));
  OntClass relation = addType(ontModel, mention, getType(RELATION));

  OntClass entity = addType(ontModel, mention, getType(ENTITY));
  OntClass event = addType(ontModel, mention, getType(EVENT));

  addRelation(ontModel, entity, entity, RELATION, "A relationship between two entities");
  addRelation(ontModel, entity, relation, SOURCE, "The source of the relationship");
  addRelation(ontModel, relation, entity, TARGET, "The target of the relationship");
  addRelation(ontModel, mention, document, MENTION_IN, "The document this is mentioned in");
  addRelation(ontModel, entity, reference, MENTION_OF, "The mention of the reference");
  addRelation(ontModel, entity, event, PARTICIPANT_IN, "A participant in the event");

  return ontModel;
}
 
Example #5
Source File: OwlSchemaFactory.java    From baleen with Apache License 2.0 5 votes vote down vote up
private Resource getRange(FeatureDescription feature) {

    String rangeTypeName = feature.getRangeTypeName();
    Resource range;
    switch (rangeTypeName) {
      case "uima.cas.Boolean":
        range = XSD.xboolean;
        break;
      case "uima.cas.Byte":
        range = XSD.xbyte;
        break;
      case "uima.cas.Short":
        range = XSD.xshort;
        break;
      case "uima.cas.Integer":
        range = XSD.xint;
        break;
      case "uima.cas.Long":
        range = XSD.xlong;
        break;
      case "uima.cas.Float":
        range = XSD.xfloat;
        break;
      case "uima.cas.Double":
        range = XSD.xdouble;
        break;
      case "uima.cas.String":
        // Fall
      default:
        range = XSD.xstring;
        break;
    }

    return range;
  }
 
Example #6
Source File: DataIDGenerator.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public Model generateDataIDModel() {
    // create an empty JENA Model
    Model model = ModelFactory.createDefaultModel();

    // setting namespaces
    model.setNsPrefix("gerbil", GERBIL.getURI());
    model.setNsPrefix("rdf", RDF.getURI());
    model.setNsPrefix("rdfs", RDFS.getURI());
    model.setNsPrefix("xsd", XSD.getURI());
    model.setNsPrefix("qb", CUBE.getURI());

    return model;
}
 
Example #7
Source File: SystemTriples.java    From shacl with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the system ontology (a shared copy).
 * @return the system ontology
 */
public static synchronized Model getVocabularyModel() {
	if (vocabulary == null) {
		vocabulary = JenaUtil.createDefaultModel();
		org.topbraid.jenax.util.JenaUtil.initNamespaces(vocabulary.getGraph());
		vocabulary.setNsPrefix("xsd", XSD.getURI());
		InputStream ttl = SystemTriples.class.getResourceAsStream("/rdf/system-triples.ttl");
		vocabulary.read(ttl, "urn:x:dummy", FileUtils.langTurtle);
		ensureSuperClasses(RDFS.Class, RDFS.Resource);
		ensureSuperClasses(OWL.Class, OWL.Thing);
		
		// Remove owl imports rdfs which only causes trouble
		vocabulary.removeAll(null, OWL.imports, null); 
		
		vocabulary.add(OWL.Thing, RDFS.subClassOf, RDFS.Resource);
		vocabulary.add(OWL.inverseOf, RDF.type, OWL.SymmetricProperty);
		vocabulary.add(OWL.equivalentClass, RDF.type, OWL.SymmetricProperty);
		vocabulary.add(OWL.equivalentProperty, RDF.type, OWL.SymmetricProperty);
		vocabulary.add(OWL.equivalentProperty, RDFS.range, RDF.Property);
		vocabulary.add(OWL.differentFrom, RDF.type, OWL.SymmetricProperty);
		vocabulary.add(OWL.sameAs, RDF.type, OWL.SymmetricProperty);
		vocabulary.add(OWL.disjointWith, RDF.type, OWL.SymmetricProperty);
		Resource xml = vocabulary.getResource(XMLLiteralType.theXMLLiteralType.getURI());
		vocabulary.add(xml, RDFS.subClassOf, RDFS.Resource);
		for(String uri : JenaDatatypes.getDatatypeURIs()) {
			Resource r = vocabulary.getResource(uri);
			if (r.getProperty(RDF.type) == null) {
				vocabulary.add(r, RDF.type, RDFS.Datatype);
				vocabulary.add(r, RDFS.subClassOf, RDFS.Literal);
			}
		}
		
		vocabulary.add(RDF.HTML, RDFS.label, "HTML");
		
		// Triples were formally in OWL 1, but dropped from OWL 2
		vocabulary.add(RDFS.comment, RDF.type, OWL.AnnotationProperty);
		vocabulary.add(RDFS.label, RDF.type, OWL.AnnotationProperty);
		vocabulary.add(RDFS.isDefinedBy, RDF.type, OWL.AnnotationProperty);
		vocabulary.add(RDFS.seeAlso, RDF.type, OWL.AnnotationProperty);
		
		// Add rdfs:labels for XSD types
		for(Resource datatype : vocabulary.listSubjectsWithProperty(RDF.type, RDFS.Datatype).toList()) {
			datatype.addProperty(RDFS.label, datatype.getLocalName());
           }
		vocabulary = JenaUtil.asReadOnlyModel(vocabulary);
	}
	return vocabulary;
}
 
Example #8
Source File: OwlSchemaFactoryTest.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Test
public void canGenerateDocumentSchema() throws CASRuntimeException, UIMAException {

  String ns = "http://baleen.dstl.gov.uk/document/";
  OwlSchemaFactory owlTypeSystem =
      new OwlSchemaFactory(ns, typeSystem, ImmutableList.of("internalId"));
  OntModel model = owlTypeSystem.createDocumentOntology();
  model.setNsPrefix("baleen", ns);

  try {
    assertNotNull(model);
    assertNotNull(model.getOntClass(ns + Document.class.getSimpleName()));
    assertNotNull(model.getOntClass(ns + ReferenceTarget.class.getSimpleName()));
    assertNotNull(model.getOntClass(ns + Relation.class.getSimpleName()));
    OntClass entity = model.getOntClass(ns + Entity.class.getSimpleName());
    assertNotNull(entity);
    assertEquals(
        "Type to represent named entities - values that are assigned a semantic type.",
        entity.getComment("EN"));

    assertNotNull(entity.getSuperClass());
    assertEquals(getEntityChildrenCount(), Streams.stream(entity.listSubClasses()).count());

    OntClass location = model.getOntClass(ns + Location.class.getSimpleName());
    assertEquals(entity, location.getSuperClass());
    assertEquals(1, Streams.stream(location.listSubClasses()).count());

    OntClass person = model.getOntClass(ns + Person.class.getSimpleName());
    assertEquals(entity, person.getSuperClass());
    assertEquals(0, Streams.stream(person.listSubClasses()).count());
    assertEquals(2, Streams.stream(person.listDeclaredProperties(true)).count());
    assertEquals(13, Streams.stream(person.listDeclaredProperties()).count());
    Optional<OntProperty> findFirst =
        Streams.stream(person.listDeclaredProperties(true))
            .filter(p -> "gender".equals(p.getLocalName()))
            .findFirst();
    assertTrue(findFirst.isPresent());
    assertEquals(XSD.xstring, findFirst.get().getRange());

    Optional<OntProperty> mentionOf =
        Streams.stream(person.listDeclaredProperties())
            .filter(p -> DocumentGraphFactory.MENTION_OF.equals(p.getLocalName()))
            .findFirst();
    assertTrue(mentionOf.isPresent());
    assertEquals(
        ReferenceTarget.class.getSimpleName(), mentionOf.get().getRange().getLocalName());

  } finally {
    writeToConsole(model);
  }
}
 
Example #9
Source File: OwlSchemaFactoryTest.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Test
public void canGenerateEntitySchema() throws ResourceInitializationException {

  String ns = "http://baleen.dstl.gov.uk/entity/";

  OwlSchemaFactory owlTypeSystem =
      new OwlSchemaFactory(ns, typeSystem, ImmutableList.of("isNormalised", "internalId"));
  OntModel model = owlTypeSystem.createEntityOntology();
  model.setNsPrefix("baleen", ns);

  try {
    assertNotNull(model);
    assertNull(model.getOntClass(ns + Document.class.getSimpleName()));
    assertNull(model.getOntClass(ns + ReferenceTarget.class.getSimpleName()));
    assertNull(model.getOntClass(ns + Relation.class.getSimpleName()));
    OntClass entity = model.getOntClass(ns + Entity.class.getSimpleName());
    assertNotNull(entity);
    assertEquals(
        "Type to represent named entities - values that are assigned a semantic type.",
        entity.getComment("EN"));

    assertNull(entity.getSuperClass());
    assertEquals(17, Streams.stream(entity.listSubClasses()).count());

    OntClass location = model.getOntClass(ns + Location.class.getSimpleName());
    assertEquals(entity, location.getSuperClass());
    assertEquals(1, Streams.stream(location.listSubClasses()).count());

    OntClass person = model.getOntClass(ns + Person.class.getSimpleName());
    assertEquals(entity, person.getSuperClass());
    assertEquals(0, Streams.stream(person.listSubClasses()).count());
    assertEquals(2, Streams.stream(person.listDeclaredProperties(true)).count());
    assertEquals(12, Streams.stream(person.listDeclaredProperties()).count());
    Optional<OntProperty> findFirst =
        Streams.stream(person.listDeclaredProperties(true))
            .filter(p -> "gender".equals(p.getLocalName()))
            .findFirst();
    Optional<OntProperty> mentions =
        Streams.stream(person.listDeclaredProperties())
            .filter(p -> "mentions".equals(p.getLocalName()))
            .findFirst();
    assertTrue(mentions.isPresent());
    assertEquals(XSD.xstring, findFirst.get().getRange());

    Optional<OntProperty> relation =
        Streams.stream(person.listDeclaredProperties())
            .filter(p -> DocumentGraphFactory.RELATION.equals(p.getLocalName()))
            .findFirst();
    assertTrue(relation.isPresent());
    assertEquals(Entity.class.getSimpleName(), relation.get().getRange().getLocalName());
    assertEquals(Entity.class.getSimpleName(), relation.get().getDomain().getLocalName());

  } finally {
    writeToConsole(model);
  }
}