-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathTask06.java
More file actions
59 lines (40 loc) · 1.77 KB
/
Copy pathTask06.java
File metadata and controls
59 lines (40 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package upm.oeg.wsld.jena;
import java.io.InputStream;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntClass;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.util.FileManager;
import org.apache.jena.vocabulary.VCARD;
/**
* Task 06: Modifying ontologies (RDFs)
*/
public class Task06 {
public static String ns = "http://somewhere#";
public static String foafNS = "http://xmlns.com/foaf/0.1/";
public static String foafEmailURI = foafNS+"email";
public static String foafKnowsURI = foafNS+"knows";
public static String stringTypeURI = "http://www.w3.org/2001/XMLSchema#string";
public static void main (String[]args){
String filename = "resources/example5.rdf";
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: " + filename + " not found");
model.read(in, null);
OntClass researcher = model.createClass(ns+"Researcher");
OntClass university = model.createClass(ns+"University");
model.getOntClass(ns+"Person").addSubClass(researcher);
Property worksIn = model.createProperty(ns + "worksIn");
Individual janeSmith = researcher.createIndividual(ns + "Jane Smith");
janeSmith.addProperty(VCARD.FN, "Jane Smith");
janeSmith.addProperty(VCARD.Given, "Jane");
janeSmith.addProperty(VCARD.Family, "Smith");
Individual upm = university.createIndividual(ns + "UPM");
Individual johnSmith = model.getIndividual(ns + "JohnSmith");
johnSmith.addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
}