forked from MiguelERuiz/Curso2017-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task06_SRC.java
70 lines (56 loc) · 2.57 KB
/
Task06_SRC.java
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
60
61
62
63
64
65
66
67
68
69
70
package ontologyapi;
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)
*
* @author t110040 -- Sergio Redondo Copado
*
*/
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 = "example5.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns + "University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
model.getOntClass(ns + "Person").addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksin = model.createProperty(ns + "worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual jSmith = researcher.createIndividual(ns + "JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
jSmith.addProperty(VCARD.FN, "Jane Smith");
jSmith.addProperty(VCARD.Given, "Jane");
jSmith.addProperty(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
/* Comento esta linea porque es mas "critica". Aqui añado una propiedad
* a John Smith, el cual se encuentra en el modelo, de que trabaja en
* la universidad, en la cual creo la UPM a no encontrarse e ella
* previamente. Uso la funcion porque me devuelve el nuevo elemento creado */
model.getIndividual(ns + "JohnSmith").addProperty(worksin, university.createIndividual(ns + "UPM"));
model.write(System.out, "RDF/XML-ABBREV");
}
}