Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Todos los assigments #642

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Assignment3/v130023-jlcastanon/Task06.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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");
}
}
70 changes: 70 additions & 0 deletions Assignment3/v130023-jlcastanon/Task07.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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.util.FileManager;
import org.apache.jena.util.iterator.ExtendedIterator;

/**
* Task 07: Querying ontologies (RDFs)
*
*/
public class Task07 {
public static String ns = "http://somewhere#";

public static void main(String args[]) {

String filename = "resources/example6.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);

System.out.println("----------Task7.1----------");

ExtendedIterator<Individual> it = model.listIndividuals();
OntClass person = model.getOntClass(ns + "Person");

while (it.hasNext()) {
Individual ind = it.next();
if (ind.hasOntClass(person))
System.out.println("|-- Individual: " + ind.getURI());
}

System.out.println("----------Task7.2----------");

ExtendedIterator<OntClass> it2 = person.listSubClasses();

while (it2.hasNext()) {
OntClass ind2 = it2.next();
System.out.println("|-- Subclass: " + ind2.getURI());
}

System.out.println("----------Task7.3----------");

OntModel modelo = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF,model);
OntClass persona = modelo.getOntClass(ns+"Person");
ExtendedIterator<OntClass> it3 = persona.listSubClasses();
ExtendedIterator<Individual> it4 = modelo.listIndividuals(persona);
while (it3.hasNext()) {
OntClass ind3 = it3.next();
System.out.println("|-- Subclasses: " + ind3.getURI());
}

while (it4.hasNext()) {
Individual indiv_instance = (Individual) it4.next();
System.out.println("|-- Instances: " + indiv_instance.getURI());
}

}
}
Loading