Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab2;
- import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
- import com.hp.hpl.jena.rdf.model.*;
- import com.hp.hpl.jena.vocabulary.VCARD;
- public class Main {
- static String URI = "http://example.com/";
- public static void main(String[] args) {
- org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
- Model model = ModelFactory.createDefaultModel();
- Model model2 = ModelFactory.createDefaultModel();
- model2.read("http://centria.di.fct.unl.pt/~cd/foaf.nt", "Turtle");
- Model res = model2.union(model);
- Resource cDamasio = addCarlos(model);
- addMe(model);
- model.write(System.out,"Turtle");
- // model.write(System.out,"RDF/XML"); // to ask
- //// iterateover(model);
- iterateoverres(res, cDamasio);
- }
- public static void iterateoverres(Model model, Resource cDamasioResource){
- StmtIterator iter = model.listStatements(null, model.getProperty("http://xmlns.com/foaf/0.1/interest"), (RDFNode)null);
- while (iter.hasNext()) {
- Statement stmt = iter.nextStatement();
- RDFNode object = stmt.getObject();
- model.read(object.toString(),"Turtle");
- }
- model.write(System.out,"Turtle");
- }
- public static Resource addCarlos(Model model){
- String cdName = "CarlosDamasio";
- String cdURI = "http://centria.di.fct.unl.pt/cd";
- Resource CD = model.createResource(URI + cdName);
- Resource cdSplittedNameResource = model.createResource();
- Resource cdTel = model.createResource();
- Property www = model.createProperty(cdURI); // to ask
- CD.addProperty(VCARD.FN, cdName);
- CD.addProperty(VCARD.N, cdSplittedNameResource);
- CD.addProperty(VCARD.TEL, cdTel);
- CD.addProperty(www, "website");
- CD.addProperty(VCARD.EMAIL, "cd@fct.unl.pt");
- CD.addProperty(VCARD.GEO, "()");
- CD.addProperty(VCARD.ADR,"Faculdade de Ciências e Tecnologia da Universidade Nova de Lisboa");
- cdSplittedNameResource.addProperty(VCARD.Given, "Carlos");
- cdSplittedNameResource.addProperty(VCARD.Family, "Damasio");
- Property extension = model.createProperty(cdURI+"/myconcepts/extension/e10758");
- Property number = model.createProperty(cdURI+"/myconcepts/number/e21948536");
- cdTel.addProperty(extension, "extension");
- cdTel.addProperty(number, "number");
- return CD;
- }
- public static void addMe(Model model){
- String pkName = "PawelKrysiak";
- Resource PK = model.createResource(URI + pkName);
- Resource pkSplittedNameResource = model.createResource();
- Property www = model.createProperty("http://w-master.cba.pl/index"); // to ask
- PK.addProperty(VCARD.FN, pkName);
- PK.addProperty(VCARD.N, pkSplittedNameResource);
- PK.addProperty(VCARD.TEL, "663571174");
- PK.addProperty(www, "website");
- PK.addProperty(VCARD.EMAIL, "p.krysiak@campus.fct.unl.pt");
- PK.addProperty(VCARD.ADR,"Residencia frausto da silva");
- pkSplittedNameResource.addProperty(VCARD.Given, "Paweł");
- pkSplittedNameResource.addProperty(VCARD.Family, "Krysiak");
- }
- public static void iterateover(Model model){
- StmtIterator iter = model.listStatements();
- // print out the predicate, subject and object of each statement
- while (iter.hasNext()) {
- Statement stmt = iter.nextStatement(); // get next statement
- Resource subject = stmt.getSubject(); // get the subject
- Property predicate = stmt.getPredicate(); // get the predicate
- RDFNode object = stmt.getObject(); // get the object
- System.out.print(subject.toString());
- System.out.print(" " + predicate.toString() + " ");
- if (object instanceof Resource) {
- System.out.print(object.toString());
- } else {
- // object is a literal
- System.out.print(" \"" + object.toString() + "\"");
- }
- System.out.println(" .");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement