Commit 6b98fe14 authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Figured out basic Jena operations with the ICE ontology.



Committing intermediate progress before tearing it all up. I have
migrated to Turtle for defining the ontology instead of RDF/XML. The
latter is just too difficult to use in my opinion. I converted the
ontology from the RDF/XML file using EasyRDF. I removed some previously
committed test files and moved other test files into the test directory.
I added a data constants class that can be used for constants commonly
required throughout the code.
Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 50e26e07
/******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
*****************************************************************************/
package org.eclipse.ice.data;
import java.util.Iterator;
import org.apache.http.client.cache.ResourceFactory;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.ObjectProperty;
import org.apache.jena.ontology.OntClass;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.NodeIterator;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.util.iterator.ExtendedIterator;
import org.apache.jena.vocabulary.VCARD;
import org.apache.jena.vocabulary.XSD;
/**
* This is a builder class for constructing Components
*
* @author Jay Jay Billings
*
*/
public class ComponentBuilder {
/**
* The ontology model from which all resources are built.
*/
private OntModel ontModel;
/**
* The base model namespace
*/
private static String namespace;
public ComponentBuilder(final OntModel ICEOntModel) {
ontModel = ICEOntModel;
namespace = ontModel.getNsPrefixURI("ice");
}
/**
* This operation executes the construction process for the Component.
*
* @return the fully initialized component based on the build parameters
*/
public Resource build(Model dataModel) {
OntClass compClass = ontModel.getOntClass(namespace + "Component");
Individual compIndividual = ontModel.createIndividual(compClass);
ObjectProperty prop = ontModel.getObjectProperty(namespace + "name");
dataModel.createResource("https://www.galactic-empire.gov/data#Comp1", compClass).addProperty(prop, "Tk-421");
return compIndividual;
}
}
/******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
*****************************************************************************/
package org.eclipse.ice.data;
/**
* This class stores ICE Data Model constants used throughout the code base.
* @author Jay Jay Billings
*
*/
public class ICEDataConstants {
/**
* Root Namespace of the ICE ontology
*/
private static String namespace = "https://www.eclipse.org/ice";
}
/******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
*****************************************************************************/
package org.eclipse.ice.data;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
/**
* The ModelFactory class is responsible for creating ICE RDF models and
* associated resources.
*
* @author Jay Jay Billings
*
*/
public class ModelFactory {
/**
* This operation creates a basic ICE data RDF model.
*
* @return the empty RDF model
*/
public Model createModel() {
Model model = null;
return model;
}
/**
* This operation returns a builder that can be used to construct a new ICE component.
* @return the Component Builder for making new components
*/
public ComponentBuilder createComponent() {
return new ComponentBuilder(null);
}
public Resource createComponent(final int id) {
Resource component = null;
return component;
}
public Resource createComponent(final int id, final String name) {
Resource component = null;
return component;
}
public Resource createComponent(final int id, final String name, final String desc) {
Resource component = null;
return component;
}
public Resource createComponent(final int id, final String name, final String desc, final String context) {
Resource component = null;
return component;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY dc "http://purl.org/dc/elements/1.1/" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY co "http://purl.org/co#" >
]>
<rdf:RDF xmlns="https://www.eclipse.org/ice#"
xmlns:adms="http://www.w3.org/ns/adms#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:co="http://purl.org/co#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<!-- ICE Ontology -->
<owl:Ontology>
<owl:versionInfo rdf:datatype="&xsd;string">1.0</owl:versionInfo>
<dc:date rdf:datatype="&xsd;string">January 19, 2019</dc:date>
<dc:contributor rdf:datatype="&xsd;string">Jay Jay Billings</dc:contributor>
<dc:format rdf:datatype="&xsd;string">application/rdf+xml</dc:format>
<dc:language>en</dc:language>
<dc:title xml:lang="en">The Eclipse Integrated Environment Data
Ontology</dc:title>
<dc:creator rdf:resource="https://www.eclipse.org/ice" />
<owl:imports
rdf:resource="http://www.w3.org/2004/02/skos/core" />
<owl:imports rdf:resource="http://purl.org/co" />
<!-- <owl:imports rdf:resource="http://www.w3.org/ns/adms"/> -->
</owl:Ontology>
<!-- Identifiable, base of data hierarchy -->
<rdf:Description
rdf:about="https://www.eclipse.org/ice#Identifiable">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class" />
<rdfs:comment xml:lang="en">This class describes objects that
are identifiable to ICE.</rdfs:comment>
<rdfs:label xml:lang="en">Identifiable</rdfs:label>
<rdfs:subClassOf
rdf:resource="http://www.w3.org/2002/07/owl#Thing" />
</rdf:Description>
<rdf:Description
rdf:about="https://www.eclipse.org/ice#context">
<rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty" />
<rdfs:comment xml:lang="en">The context can be thought of as
an additional clue that can be provided with the object to allow
clients to interpret its contents in a slightly different way.</rdfs:comment>
<rdfs:domain
rdf:resource="https://www.eclipse.org/ice#Identifiable" />
<rdfs:label xml:lang="en">context</rdfs:label>
<rdfs:range
rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty" />
</rdf:Description>
<rdf:Description
rdf:about="https://www.eclipse.org/ice#identifier">
<rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty" />
<rdfs:comment xml:lang="en">A unique identifier for the
object.</rdfs:comment>
<rdfs:domain
rdf:resource="https://www.eclipse.org/ice#Identifiable" />
<rdfs:label xml:lang="en">id</rdfs:label>
<rdfs:range
rdf:resource="http://www.w3.org/2001/XMLSchema#long" />
<!-- <rdfs:range rdf:resource="http://www.w3.org/ns/adms#identifier"/> -->
</rdf:Description>
<rdf:Description
rdf:about="https://www.eclipse.org/ice#name">
<rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty" />
<rdfs:comment xml:lang="en">The name that should be given to
the Identifiable entity.</rdfs:comment>
<rdfs:domain
rdf:resource="https://www.eclipse.org/ice#Identifiable" />
<rdfs:label xml:lang="en">name</rdfs:label>
<rdfs:range
rdf:resource="http://www.w3.org/2001/XMLSchema#string" />
</rdf:Description>
<rdf:Description
rdf:about="https://www.eclipse.org/ice#desc">
<rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty" />
<rdfs:comment xml:lang="en">The description that should be
given to the Identifiable entity.</rdfs:comment>
<rdfs:domain
rdf:resource="https://www.eclipse.org/ice#Identifiable" />
<rdfs:label xml:lang="en">description</rdfs:label>
<rdfs:range
rdf:resource="http://www.w3.org/2001/XMLSchema#string" />
</rdf:Description>
<!-- Component - base of data-holding components such as data component,
etc. in Form -->
<rdf:Description
rdf:about="https://www.eclipse.org/ice#Component">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class" />
<rdfs:comment xml:lang="en">Components are special types of
Identifiables that manage or share data, and which act as nodes in
the Form (a tree).</rdfs:comment>
<rdfs:label xml:lang="en">Component</rdfs:label>
<rdfs:subClassOf
rdf:resource="https://www.eclipse.org/ice#Identifiable" />
</rdf:Description>
<!-- Composite - Root and parent nodes in Form (tree). -->
<rdf:Description
rdf:about="https://www.eclipse.org/ice#Composite">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class" />
<rdfs:comment xml:lang="en">Composites hold collections of
Components to store data and are the root and parent nodes in the
Form data tree.</rdfs:comment>
<rdfs:label xml:lang="en">Composite</rdfs:label>
<rdfs:subClassOf
rdf:resource="https://www.eclipse.org/ice#Component" />
</rdf:Description>
<!-- ComponentList - The class that defines the list of components found
on the composite. -->
<owl:Class
rdf:about="https://www.eclipse.org/ice#ComponentList">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class" />
<rdfs:comment xml:lang="en">The list of components associated
with the composite.</rdfs:comment>
<rdfs:label xml:lang="en">ComponentList</rdfs:label>
<rdfs:subClassOf rdf:resource="http://purl.org/co#Set" />
<!-- Note that a second subClassOf block is required by the parser. Properties
cannot go in the first subClassOf block, apparently. Failure to do so will
cause Apache Jena, for example, to produce an error saying that "The attributes
on this property element, are not permitted with any content; expecting end
element tag." -->
<rdfs:subClassOf>
<!-- Restrict the element type of the list to be a Component -->
<owl:Restriction>
<owl:onProperty
rdf:resource="http://purl.org/co#element" />
<owl:allValuesFrom
rdf:resource="https://www.eclipse.org/ice#Component" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<!-- The property declaring the membership of and range relationship between
Composite and ComponentList. -->
<owl:ObjectProperty
rdf:about="https://www.eclipse.org/ice#componentListProperty">
<rdfs:comment xml:lang="en">The link between the Composite and
ComponentList.</rdfs:comment>
<rdfs:domain
rdf:resource="https://www.eclipse.org/ice#Composite" />
<rdfs:label xml:lang="en">componentListProperty</rdfs:label>
<rdfs:range
rdf:resource="https://www.eclipse.org/ice#ComponentList"></rdfs:range>
</owl:ObjectProperty>
</rdf:RDF>
\ No newline at end of file
......@@ -6,6 +6,7 @@
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ex: <http://example.com/ns#> .
@prefix ice: <https://www.eclipse.org/ice#> .
<https://www.eclipse.org/ice#Identifiable>
a owl:Class ;
......@@ -100,20 +101,3 @@
Ontology"""@en ;
dc11:creator <https://www.eclipse.org/ice> ;
owl:imports <http://www.w3.org/2004/02/skos/core>, <http://purl.org/co> .
ex:PersonShape
a sh:NodeShape ;
sh:targetClass ex:Person ; # Applies to all persons
sh:property [ # _:b1
sh:path ex:ssn ; # constrains the values of ex:ssn
sh:maxCount 1 ;
sh:datatype xsd:string ;
sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ;
] ;
sh:property [ # _:b2
sh:path ex:worksFor ;
sh:class ex:Company ;
sh:nodeKind sh:IRI ;
] ;
sh:closed true ;
sh:ignoredProperties ( rdf:type ) .
@prefix ex: <http://example.com/ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Alice
a ex:Person ;
ex:ssn "987-65-432A" .
ex:Bob
a ex:Person ;
ex:ssn "123-45-6789" ;
ex:ssn "124-35-6789" .
ex:Calvin
a ex:Person ;
ex:birthDate "1971-07-07"^^xsd:date ;
ex:worksFor ex:UntypedCompany .
@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://example.com/ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:PersonShape
a sh:NodeShape ;
sh:targetClass ex:Person ; # Applies to all persons
sh:property [ # _:b1
sh:path ex:ssn ; # constrains the values of ex:ssn
sh:maxCount 1 ;
sh:datatype xsd:string ;
sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ;
] ;
sh:property [ # _:b2
sh:path ex:worksFor ;
sh:class ex:Company ;
sh:nodeKind sh:IRI ;
] ;
sh:closed true ;
sh:ignoredProperties ( rdf:type ) .
/******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
*****************************************************************************/
package org.eclipse.ice.tests.data;
import static org.junit.Assert.*;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.util.FileManager;
import org.eclipse.ice.data.ComponentBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* This class tests {@link ComponentBuilder}.
*
* @author Jay Jay Billings
*/
public class ComponentBuilderTest {
// Reference ICE ontology
protected static OntModel ICEOntModel;
// Component builder test instance
protected static ComponentBuilder builder;
// Test data model
protected static Model dataModel;
// Ontology namespace
protected String namespace = "https://www.eclipse.org/ice#";
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// Load the ontology
Model baseModel = FileManager.get().loadModel("data/ice-owl.ttl", null, "TURTLE");
// No need for a complicated inferencer
ICEOntModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel);
// Setup the builder that is used for *all* the tests. Note that the ontology is
// injected.
builder = new ComponentBuilder(ICEOntModel);
// Setup the default data model for the test. Note that this is different than
// the ontology model in that it will be filled with data based on the ontology.
dataModel = ModelFactory.createDefaultModel();
}
/**
* This operation insures that the build() operation works.
*/
@Test
public void testBuild() {
Resource comp = null;
comp = builder.build(dataModel);
// Make sure the component exists
assertNotNull(comp);
// Check the namespace
assertEquals(namespace, comp.getNameSpace());
// I don't know if namespaces make sense as
// Print the properties to examine them
System.out.println("-----");
for (StmtIterator foo = comp.listProperties(); foo.hasNext();) {
System.out.println(foo.next().toString());
}
return;
}
}
......@@ -38,7 +38,7 @@ public class ExampleAPI_ICE_01 {
public static void main(String[] args) {
FileManager.get().addLocatorClassLoader(ExampleAPI_ICE_01.class.getClassLoader());
Model model = FileManager.get().loadModel("/home/bkj/ICEIII/ice/org.eclipse.ice.data.owl/test.rdf", null, "RDF/XML");
Model model = FileManager.get().loadModel("/home/bkj/ICEIII/ice/org.eclipse.ice.data/src/main/resources/data/test.rdf", null, "RDF/XML");
// String queryString = "PREFIX example: <http://example.org/>" +
// "PREFIX foaf: <h ttp://xmlns.com/foaf/0.1/>" +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment