public static void main(String args[]) { // some definitions String personURI = "http://somewhere/JohnSmith"; String givenName = "John"; String familyName = "Smith"; String fullName = givenName + " " + familyName; // create an empty model Model model = ModelFactory.createDefaultModel(); // create the resource // and add the properties cascading style Resource johnSmith = model .createResource(personURI) .addProperty(VCARD.FN, fullName) .addProperty( VCARD.N, model .createResource() .addProperty(VCARD.Given, givenName) .addProperty(VCARD.Family, familyName)); // now write the model in XML form to a file model.write(System.out); }
@Override protected Serializable processMethod() throws AsyncException { for (Iterator<String> iter = altLocations.keySet().iterator(); iter.hasNext(); ) { Resource r = model.createResource(); Resource e = model.createResource(); model.add(getHandler(""), r, LocationMappingVocab.mapping, e); String k = iter.next(); String v = altLocations.get(k); model.add(getHandler(""), e, LocationMappingVocab.name, k); model.add(getHandler(""), e, LocationMappingVocab.altName, v); } for (Iterator<String> iter = altPrefixes.keySet().iterator(); iter.hasNext(); ) { Resource r = model.createResource(); Resource e = model.createResource(); model.add(getHandler(""), r, LocationMappingVocab.mapping, e); String k = iter.next(); String v = altPrefixes.get(k); model.add(getHandler(""), e, LocationMappingVocab.prefix, k); model.add(getHandler(""), e, LocationMappingVocab.altPrefix, v); } return null; }
public void setUp() { model = getModel(); Resource S2 = model.createResource(anchor + "subject2"); S = model.createResource(anchor + "subject"); P = model.createProperty(anchor + "predicate"); O = model.createLiteral(anchor + "object"); SPO = model.createStatement(S, P, O); SPO2 = model.createStatement(S2, P, O); }
/** * Example the conclusions graph for introduction of restrictions which require a comprehension * rewrite and declare new (anon) classes for those restrictions. */ public void comprehensionAxioms(Model premises, Model conclusions) { // Comprehend all restriction declarations and note them in a map Map<Resource, Resource> comprehension = new HashMap<>(); StmtIterator ri = conclusions.listStatements(null, RDF.type, OWL.Restriction); while (ri.hasNext()) { Resource restriction = ri.nextStatement().getSubject(); StmtIterator pi = restriction.listProperties(OWL.onProperty); while (pi.hasNext()) { Resource prop = (Resource) pi.nextStatement().getObject(); StmtIterator vi = restriction.listProperties(); while (vi.hasNext()) { Statement rs = vi.nextStatement(); if (!rs.getPredicate().equals(OWL.onProperty)) { // Have a restriction on(prop) of type rs in the conclusions // So assert a premise that such a restriction could exisit Resource comp = premises .createResource() .addProperty(RDF.type, OWL.Restriction) .addProperty(OWL.onProperty, prop) .addProperty(rs.getPredicate(), rs.getObject()); comprehension.put(restriction, comp); } } } } // Comprehend any intersectionOf lists. Introduce anon class which has the form // of the intersection expression. // Rewrite queries of the form (X intersectionOf Y) to the form // (X equivalentClass ?CC) (?CC intersectionOf Y) StmtIterator ii = conclusions.listStatements(null, OWL.intersectionOf, (RDFNode) null); List<Statement> intersections = new ArrayList<>(); while (ii.hasNext()) { intersections.add(ii.nextStatement()); } for (Statement is : intersections) { // Declare in the premises that such an intersection exists Resource comp = premises .createResource() .addProperty(RDF.type, OWL.Class) .addProperty( OWL.intersectionOf, mapList(premises, (Resource) is.getObject(), comprehension)); // Rewrite the conclusions to be a test for equivalence between the class being // queried and the comprehended interesection conclusions.remove(is); conclusions.add(is.getSubject(), OWL.equivalentClass, comp); } // Comprehend any oneOf lists StmtIterator io = conclusions.listStatements(null, OWL.oneOf, (RDFNode) null); while (io.hasNext()) { Statement s = io.nextStatement(); Resource comp = premises.createResource().addProperty(OWL.oneOf, s.getObject()); } }
public void testQuintetOfQuadlets() { Resource rs = model.createResource(); rs.addProperty(RDF.type, RDF.Statement); model.createResource().addProperty(RDF.value, rs); rs.addProperty(RDF.subject, model.createResource()); rs.addProperty(RDF.predicate, model.createProperty("http://example.org/foo")); rs.addProperty(RDF.object, model.createResource()); rs.addProperty(RDF.object, model.createResource()); StmtIterator it = model.listStatements(); while (it.hasNext()) { Statement s = it.nextStatement(); assertFalse(s.getObject().equals(s.getSubject())); } }
protected void setUp() throws java.lang.Exception { conn = TestConnection.makeAndCleanTestConnection(); model = ModelRDB.createModel(conn, TestPackage.M_DB); model .createResource() .addProperty(RDF.type, RDFS.Resource) .addProperty(RDFS.label, "foo") .addProperty(RDF.value, "123"); model .createResource() .addProperty(RDF.type, RDFS.Resource) .addProperty(RDFS.label, "bar") .addProperty(RDF.value, "123"); }
/** "dirty" reifications - those with conflicting quadlets - should fail. */ public void testDirtyReification() { Resource R = model.createResource(aURI); model.add(R, RDF.type, RDF.Statement); model.add(R, RDF.subject, S); model.add(R, RDF.subject, P); testDoesNotReify("boo", R); }
public static String RenderTemplatePage(Bindings b, String templateName) throws IOException { MediaType mt = MediaType.TEXT_HTML; Resource config = model.createResource("eh:/root"); Mode prefixMode = Mode.PreferPrefixes; ShortnameService sns = new StandardShortnameService(); List<Resource> noResults = CollectionUtils.list(root.inModel(model)); Graph resultGraph = graphModel.getGraph(); resultGraph.getPrefixMapping().setNsPrefix("api", API.NS); resultGraph.add(Triple.create(root.asNode(), API.items.asNode(), RDF.nil.asNode())); APIResultSet rs = new APIResultSet(resultGraph, noResults, true, true, "details", View.ALL); VelocityRenderer vr = new VelocityRenderer(mt, null, config, prefixMode, sns); VelocityRendering vx = new VelocityRendering(b, rs, vr); VelocityEngine ve = vx.createVelocityEngine(); VelocityContext vc = vx.createVelocityContext(b); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Writer w = new OutputStreamWriter(bos, "UTF-8"); Template t = ve.getTemplate(templateName); t.merge(vc, w); w.close(); return bos.toString(); }
private void testNotReifying(Model m, String uri) { try { m.createResource(uri).as(ReifiedStatement.class); fail("there should be no reifiedStatement for " + uri); } catch (DoesNotReifyException e) { /* that's what we require */ } }
/** * check that, from a model with any combination of the statements given, we can convert R into a * ReifiedStatement iff the four components of the quad are in the model. */ public void testReificationCombinations() { Resource RR = model.createResource(aURI), SS = model.createResource(anotherURI); Property PP = (Property) RR.as(Property.class); Object[][] statements = { {model.createStatement(RR, RDF.type, RDF.Statement), new Integer(1)}, {model.createStatement(RR, RDF.subject, SS), new Integer(2)}, {model.createStatement(RR, RDF.predicate, PP), new Integer(4)}, {model.createStatement(RR, RDF.object, O), new Integer(8)}, {model.createStatement(SS, PP, O), new Integer(16)}, {model.createStatement(RR, PP, O), new Integer(32)}, {model.createStatement(SS, RDF.subject, SS), new Integer(64)}, {model.createStatement(SS, RDF.predicate, PP), new Integer(128)}, {model.createStatement(SS, RDF.object, O), new Integer(256)}, {model.createStatement(SS, RDF.type, RDF.Statement), new Integer(512)} }; if (model.getReificationStyle() != ModelFactory.Minimal) testCombinations(model, RR, 0, statements, statements.length); }
public static void main(String args[]) { OntModel m = ModelFactory.createOntologyModel(); OntDocumentManager dm = m.getDocumentManager(); dm.addAltEntry( "http://www.eswc2006.org/technologies/ontology", "file:" + JENA + "src/examples/resources/eswc-2006-09-21.rdf"); m.read("http://www.eswc2006.org/technologies/ontology"); // create an empty model Model model = ModelFactory.createDefaultModel(); // create the resource Resource johnSmith = model.createResource(personURI); // add the property johnSmith.addProperty(VCARD.FN, fullName); johnSmith.addProperty( VCARD.N, model.createResource().addProperty(VCARD.Given, "jon").addProperty(VCARD.Family, "Smit")); // list the statements in the 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(" ."); } }
public static void main(String args[]) { // create an empty model Model model = ModelFactory.createDefaultModel(); // create the resource Resource johnSmith = model.createResource(personURI); // add the property johnSmith.addProperty(VCARD.FN, fullName); }
public void testIsReified() { ReifiedStatement rs = model.createReifiedStatement(aURI, SPO); Resource BS = model.createResource(anchor + "BS"); Property BP = model.createProperty(anchor + "BP"); RDFNode BO = model.createProperty(anchor + "BO"); model.add(rs, P, O); assertTrue("st should be reified now", SPO.isReified()); assertTrue("m should have st reified now", model.isReified(SPO)); assertFalse( "this new statement should not be reified", model.createStatement(BS, BP, BO).isReified()); }
/** * the simplest case: if we assert all the components of a reification quad, we can get a * ReifiedStatement that represents the reified statement. */ public void testBasicReification() { if (model.getReificationStyle() != ModelFactory.Minimal) { Resource R = model.createResource(aURI); model.add(R, RDF.type, RDF.Statement); model.add(R, RDF.subject, S); model.add(R, RDF.predicate, P); model.add(R, RDF.object, O); RDFNode rs = R.as(ReifiedStatement.class); assertEquals("can recover statement", SPO, ((ReifiedStatement) rs).getStatement()); } }
/** * Vocabulary definitions from * /home/reto/workspace/wymiwyg-commons-jena/src/org/wymiwyg/commons/vocabulary/foaf-extensions.rdf * * @author Auto-generated by schemagen on 31 Mai 2007 01:33 */ public class FOAFEX { /** The RDF model that holds the vocabulary terms */ private static Model m_model = ModelFactory.createDefaultModel(); /** The namespace of the vocabulary as a string */ public static final String NS = "http://wymiwyg.org/ontologies/foaf/extensions#"; /** * The namespace of the vocabulary as a string * * @see #NS */ public static String getURI() { return NS; } /** The namespace of the vocabulary as a resource */ public static final Resource NAMESPACE = m_model.createResource(NS); /** * Indicates a document which has the subject as primary-topic and is a * foaf:PersonalProfileDocument */ public static final Property personalProfileDocument = m_model.createProperty( "http://wymiwyg.org/ontologies/foaf/extensions#personalProfileDocument"); /** Indicates a document which has the subject as primary-topic */ public static final Property agentDescriptionDocument = m_model.createProperty( "http://wymiwyg.org/ontologies/foaf/extensions#agentDescriptionDocument"); /** inverse of foaf:knows */ public static final Property knownBy = m_model.createProperty("http://wymiwyg.org/ontologies/foaf/extensions#knownBy"); /** A document with a foaf:Agent as foaf:primarySubject */ public static final Resource AgentProfileDocument = m_model.createResource("http://wymiwyg.org/ontologies/foaf/extensions#AgentProfileDocument"); }
/** * Helper. Adds to the target model a translation of the given RDF list with each element replaced * according to the map. */ private Resource mapList(Model target, Resource list, Map<Resource, Resource> map) { if (list.equals(RDF.nil)) { return RDF.nil; } else { Resource head = (Resource) list.getRequiredProperty(RDF.first).getObject(); Resource rest = (Resource) list.getRequiredProperty(RDF.rest).getObject(); Resource mapElt = target.createResource(); Resource mapHead = map.get(head); if (mapHead == null) mapHead = head; mapElt.addProperty(RDF.first, mapHead); mapElt.addProperty(RDF.rest, mapList(target, rest, map)); return mapElt; } }
/** Initialize the result model. */ public void initResults() { testResults = ModelFactory.createDefaultModel(); jena2 = testResults.createResource(BASE_RESULTS_URI + "#jena2"); jena2.addProperty( RDFS.comment, testResults.createLiteral( "<a xmlns=\"http://www.w3.org/1999/xhtml\" href=\"http://jena.sourceforce.net/\">Jena2</a> includes a rule-based inference engine for RDF processing, " + "supporting both forward and backward chaining rules. Its OWL rule set is designed to provide sound " + "but not complete instance resasoning for that fragment of OWL/Full limited to the OWL/lite vocabulary. In" + "particular it does not support unionOf/complementOf.", true)); jena2.addProperty(RDFS.label, "Jena2"); testResults.setNsPrefix("results", OWLResults.NS); }
/** * Check that a predicate for which no shortnames are defined in name map still gets a term * binding in the metadata. */ @Test public void testTermBindingsCoverAllPredicates() throws URISyntaxException { Resource thisPage = ResourceFactory.createResource("elda:thisPage"); String pageNumber = "1"; Bindings cc = new Bindings(); URI reqURI = new URI(""); // EndpointDetails spec = new EndpointDetails() { @Override public boolean isListEndpoint() { return true; } @Override public boolean hasParameterBasedContentNegotiation() { return false; } }; EndpointMetadata em = new EndpointMetadata(spec, thisPage, pageNumber, cc, reqURI); // PrefixMapping pm = PrefixMapping.Factory.create().setNsPrefix("this", "http://example.com/root#"); Model toScan = ModelIOUtils.modelFromTurtle(":a <http://example.com/root#predicate> :b."); toScan.setNsPrefixes(pm); Resource predicate = toScan.createProperty("http://example.com/root#predicate"); Model meta = ModelFactory.createDefaultModel(); Resource exec = meta.createResource("fake:exec"); ShortnameService sns = new StandardShortnameService(); // APIEndpoint.Request r = new APIEndpoint.Request( new Controls(), reqURI, cc ); CompleteContext c = new CompleteContext(CompleteContext.Mode.PreferPrefixes, sns.asContext(), pm) .include(toScan); em.addTermBindings(toScan, meta, exec, c); @SuppressWarnings("unused") Map<String, String> termBindings = c.Do(); Resource tb = meta.listStatements(null, API.termBinding, Any).nextStatement().getResource(); assertTrue(meta.contains(tb, API.label, "this_predicate")); assertTrue(meta.contains(tb, API.property, predicate)); }
/** Run a single test of any sort, performing any appropriate logging and error reporting. */ public void runTest(Resource test) { System.out.println("Running " + test); boolean success = false; boolean fail = false; try { success = doRunTest(test); } catch (Exception e) { fail = true; System.out.print("\nException: " + e); e.printStackTrace(); } testCount++; if (success) { System.out.print((testCount % 40 == 0) ? ".\n" : "."); System.out.flush(); passCount++; } else { System.out.println("\nFAIL: " + test); } Resource resultType = null; if (fail) { resultType = OWLResults.FailingRun; } else { if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest) || test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) { resultType = success ? OWLResults.PassingRun : OWLResults.FailingRun; } else { resultType = success ? OWLResults.PassingRun : OWLResults.IncompleteRun; } } // log to the rdf result format Resource result = testResults .createResource() .addProperty(RDF.type, OWLResults.TestRun) .addProperty(RDF.type, resultType) .addProperty(OWLResults.test, test) .addProperty(OWLResults.system, jena2); }
/** * Vocabulary definitions from http://annotation.semanticweb.org/iswc/iswc.daml * * @author Auto-generated by schemagen on 06 Sep 2006 20:19 */ public class ISWC { /** The RDF model that holds the vocabulary terms */ private static Model m_model = ModelFactory.createDefaultModel(); /** The namespace of the vocabulary as a string */ public static final String NS = "http://annotation.semanticweb.org/iswc/iswc.daml#"; /** * The namespace of the vocabulary as a string * * @see #NS */ public static String getURI() { return NS; } /** The namespace of the vocabulary as a resource */ public static final Resource NAMESPACE = m_model.createResource(NS); public static final Property persons_involved = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#persons_involved"); public static final Property conference = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#conference"); public static final Property formal_language = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#formal_language"); public static final Property application_domain = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#application_domain"); public static final Property algorithm = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#algorithm"); public static final Property tool = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#tool"); public static final Property hasSubtopic = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#hasSubtopic"); public static final Property has_affiliate = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#has_affiliate"); public static final Property is_about = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#is_about"); public static final Property funding_by = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#funding_by"); public static final Property involved_in_project = m_model.createProperty( "http://annotation.semanticweb.org/iswc/iswc.daml#involved_in_project"); public static final Property application = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#application"); public static final Property has_affiliation = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#has_affiliation"); public static final Property topic = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#topic"); public static final Property author = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#author"); public static final Property organizations_involved = m_model.createProperty( "http://annotation.semanticweb.org/iswc/iswc.daml#organizations_involved"); public static final Property research_topics = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#research_topics"); public static final Property method = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#method"); public static final Property name = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#name"); public static final Property phone = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#phone"); public static final Property country = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#country"); public static final Property location = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#location"); public static final Property email = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#email"); public static final Property eventTitle = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#eventTitle"); public static final Property address = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#address"); public static final Property fax = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#fax"); public static final Property first_Name = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#first_Name"); public static final Property title = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#title"); public static final Property year = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#year"); public static final Property middle_Initial = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#middle_Initial"); public static final Property date = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#date"); public static final Property project_title = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#project_title"); public static final Property last_Name = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#last_Name"); public static final Property photo = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#photo"); public static final Property homepage = m_model.createProperty("http://annotation.semanticweb.org/iswc/iswc.daml#homepage"); public static final Resource Researcher = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Researcher"); public static final Resource Research_Funding_Institution = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Research_Funding_Institution"); public static final Resource Formal_Language = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Formal_Language"); public static final Resource Event = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Event"); public static final Resource Algorithm = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Algorithm"); public static final Resource Application = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Application"); public static final Resource Faculty_Member = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Faculty_Member"); public static final Resource Full_Professor = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Full_Professor"); public static final Resource Organization = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Organization"); public static final Resource Association = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Association"); public static final Resource Tutorial = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Tutorial"); public static final Resource Employee = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Employee"); public static final Resource Proceedings = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Proceedings"); public static final Resource University = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#University"); public static final Resource PhDStudent = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#PhDStudent"); public static final Resource Topic = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Topic"); public static final Resource Application_Domain = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Application_Domain"); public static final Resource Institute = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Institute"); public static final Resource Enterprise = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Enterprise"); public static final Resource Project = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Project"); public static final Resource Associate_Professor = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Associate_Professor"); public static final Resource Person = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Person"); public static final Resource Book = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Book"); public static final Resource Method = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Method"); public static final Resource Lecturer = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Lecturer"); public static final Resource Tool = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Tool"); public static final Resource Student = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Student"); public static final Resource Report = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Report"); public static final Resource Conference = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Conference"); public static final Resource InProceedings = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#InProceedings"); public static final Resource Department = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Department"); public static final Resource Workshop = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Workshop"); public static final Resource Publication = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Publication"); public static final Resource Development_of_Knowledge_Management_Systems = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Development_of_Knowledge_Management_Systems"); public static final Resource e_Business = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#e-Business"); public static final Resource Knowledge_Reasoning = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Reasoning"); public static final Resource Knowledge_Discovery = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Discovery"); public static final Resource Text_Mining = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Text_Mining"); public static final Resource World_Wide_Web = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#World_Wide_Web"); public static final Resource C = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#C"); public static final Resource OXML = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#OXML"); public static final Resource Knowledge_Systems = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Systems"); public static final Resource Web_Services = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Web_Services"); public static final Resource Information_Systems = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Information_Systems"); public static final Resource Agents = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Agents"); public static final Resource Logic = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Logic"); public static final Resource Information_Extraction = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Information_Extraction"); public static final Resource Agent_Systems = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Agent_Systems"); public static final Resource Knowledge_Management = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Management"); public static final Resource DAML_OIL = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#DAML_OIL"); public static final Resource Artificial_Intelligence = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Artificial_Intelligence"); public static final Resource Semantic_Web = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Semantic_Web"); public static final Resource KAON = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#KAON"); public static final Resource Databases = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Databases"); public static final Resource RDFS = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#RDFS"); public static final Resource ISWC_2002 = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#ISWC_2002"); public static final Resource Data_Mining = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Data_Mining"); public static final Resource Knowledge_Portals = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Portals"); public static final Resource TowardsSemanticWebMining = m_model.createResource( "http://annotation.semanticweb.org/iswc/Towards_Semantic_Web_Mining.html#TowardsSemanticWebMining"); public static final Resource Knowledge_Management_Methodology = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Management_Methodology"); public static final Resource Knowledge_Representation_Languages = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Representation_Languages"); public static final Resource Ontology_Learning = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Ontology_Learning"); public static final Resource Ontology_based_Knowledge_Management_Systems = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Ontology-based_Knowledge_Management_Systems"); public static final Resource XML = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#XML"); public static final Resource Machine_Learning = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Machine_Learning"); public static final Resource Network_Infrastructure = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Network_Infrastructure"); public static final Resource Modeling = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Modeling"); public static final Resource SQL = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#SQL"); public static final Resource Business_Engineering = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Business_Engineering"); public static final Resource Information_Retrieval = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Information_Retrieval"); public static final Resource Office_Information_Systems = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Office_Information_Systems"); public static final Resource RDF = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#RDF"); public static final Resource Semantic_Annotation = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Semantic_Annotation"); public static final Resource Java = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Java"); public static final Resource Knowledge_Representation_And_Reasoning = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Knowledge_Representation_And_Reasoning"); public static final Resource Semantic_Web_Iinfrastructure = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Semantic_Web_Iinfrastructure"); public static final Resource Query_Languages = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Query_Languages"); public static final Resource Matching = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#Matching"); public static final Resource Human_Computer_Interaction = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Human_Computer_Interaction"); public static final Resource Semantic_Web_Languages = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Semantic_Web_Languages"); public static final Resource Ontology_Engineering = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#Ontology_Engineering"); public static final Resource University_of_Karlsruhe = m_model.createResource( "http://annotation.semanticweb.org/iswc/iswc.daml#University_of_Karlsruhe"); public static final Resource AIFB = m_model.createResource("http://annotation.semanticweb.org/iswc/iswc.daml#AIFB"); }
private Resource createMetadata(final boolean isListEndpoint, Integer totalResults) throws URISyntaxException { Model objectModel = ModelFactory.createDefaultModel(); MergedModels mergedModels = new MergedModels(objectModel); // Model meta = mergedModels.getMetaModel(); // Resource thisMetaPage = meta.createResource("eh:/thisMetaPage"); Resource SEP = meta.createResource("eh:/sparqlEndpoint"); thisMetaPage.addProperty(API.sparqlEndpoint, SEP); Bindings bindings = new Bindings(); URI ru = new URI(thisMetaPage.getURI()); Resource uriForDefinition = objectModel.createResource(thisMetaPage.getURI()); boolean suppressIPTO = true; int page = 1, perPage = 10; boolean hasMorePages = true; Context context = new Context(); CompleteContext cc = new CompleteContext(Mode.PreferLocalnames, context, objectModel); // SetsMetadata setsMeta = new SetsMetadata() { @Override public void setMetadata(String type, Model meta) {} }; WantsMetadata wantsMeta = new WantsMetadata() { @Override public boolean wantsMetadata(String name) { return true; } }; // Map<String, View> views = new HashMap<String, View>(); Set<FormatNameAndType> formats = new HashSet<FormatNameAndType>(); // EndpointDetails details = new EndpointDetails() { @Override public boolean isListEndpoint() { return isListEndpoint; } @Override public boolean hasParameterBasedContentNegotiation() { return false; } }; // EndpointMetadata.addAllMetadata( mergedModels, ru, uriForDefinition, bindings, cc, suppressIPTO, thisMetaPage, page, perPage, totalResults, hasMorePages, CollectionUtils.list(objectModel.createResource("eh:/item/_1")), setsMeta, wantsMeta, "SELECT", "VIEW", new TestCaches.FakeSource("Nemos"), views, formats, details); return thisMetaPage; }
/** Vocabulary definitions from file:vocabularies/owl.owl */ public class OWL { /** The RDF model that holds the vocabulary terms */ private static Model m_model = ModelFactory.createDefaultModel(); /** The namespace of the vocabulary as a string ({@value}) */ public static final String NS = "http://www.w3.org/2002/07/owl#"; /** * The namespace of the vocabulary as a string * * @see #NS */ public static String getURI() { return NS; } /** The namespace of the vocabulary as a resource */ public static final Resource NAMESPACE = m_model.createResource(NS); /** A resource that denotes the OWL-full sublanguage of OWL */ public static final Resource FULL_LANG = m_model.getResource(getURI()); /** A resource, not officially sanctioned by WebOnt, that denotes the OWL-DL sublanguage of OWL */ public static final Resource DL_LANG = m_model.getResource("http://www.w3.org/TR/owl-features/#term_OWLDL"); /** * A resource, not officially sanctioned by WebOnt, that denotes the OWL-Lite sublanguage of OWL */ public static final Resource LITE_LANG = m_model.getResource("http://www.w3.org/TR/owl-features/#term_OWLLite"); // Vocabulary properties /////////////////////////// public static final Property maxCardinality = m_model.createProperty("http://www.w3.org/2002/07/owl#maxCardinality"); public static final Property versionInfo = m_model.createProperty("http://www.w3.org/2002/07/owl#versionInfo"); public static final Property equivalentClass = m_model.createProperty("http://www.w3.org/2002/07/owl#equivalentClass"); public static final Property distinctMembers = m_model.createProperty("http://www.w3.org/2002/07/owl#distinctMembers"); public static final Property oneOf = m_model.createProperty("http://www.w3.org/2002/07/owl#oneOf"); public static final Property sameAs = m_model.createProperty("http://www.w3.org/2002/07/owl#sameAs"); public static final Property incompatibleWith = m_model.createProperty("http://www.w3.org/2002/07/owl#incompatibleWith"); public static final Property minCardinality = m_model.createProperty("http://www.w3.org/2002/07/owl#minCardinality"); public static final Property complementOf = m_model.createProperty("http://www.w3.org/2002/07/owl#complementOf"); public static final Property onProperty = m_model.createProperty("http://www.w3.org/2002/07/owl#onProperty"); public static final Property equivalentProperty = m_model.createProperty("http://www.w3.org/2002/07/owl#equivalentProperty"); public static final Property inverseOf = m_model.createProperty("http://www.w3.org/2002/07/owl#inverseOf"); public static final Property backwardCompatibleWith = m_model.createProperty("http://www.w3.org/2002/07/owl#backwardCompatibleWith"); public static final Property differentFrom = m_model.createProperty("http://www.w3.org/2002/07/owl#differentFrom"); public static final Property priorVersion = m_model.createProperty("http://www.w3.org/2002/07/owl#priorVersion"); public static final Property imports = m_model.createProperty("http://www.w3.org/2002/07/owl#imports"); public static final Property allValuesFrom = m_model.createProperty("http://www.w3.org/2002/07/owl#allValuesFrom"); public static final Property unionOf = m_model.createProperty("http://www.w3.org/2002/07/owl#unionOf"); public static final Property hasValue = m_model.createProperty("http://www.w3.org/2002/07/owl#hasValue"); public static final Property someValuesFrom = m_model.createProperty("http://www.w3.org/2002/07/owl#someValuesFrom"); public static final Property disjointWith = m_model.createProperty("http://www.w3.org/2002/07/owl#disjointWith"); public static final Property cardinality = m_model.createProperty("http://www.w3.org/2002/07/owl#cardinality"); public static final Property intersectionOf = m_model.createProperty("http://www.w3.org/2002/07/owl#intersectionOf"); // Vocabulary classes /////////////////////////// public static final Resource Thing = m_model.createResource("http://www.w3.org/2002/07/owl#Thing"); public static final Resource DataRange = m_model.createResource("http://www.w3.org/2002/07/owl#DataRange"); public static final Resource Ontology = m_model.createResource("http://www.w3.org/2002/07/owl#Ontology"); public static final Resource DeprecatedClass = m_model.createResource("http://www.w3.org/2002/07/owl#DeprecatedClass"); public static final Resource AllDifferent = m_model.createResource("http://www.w3.org/2002/07/owl#AllDifferent"); public static final Resource DatatypeProperty = m_model.createResource("http://www.w3.org/2002/07/owl#DatatypeProperty"); public static final Resource SymmetricProperty = m_model.createResource("http://www.w3.org/2002/07/owl#SymmetricProperty"); public static final Resource TransitiveProperty = m_model.createResource("http://www.w3.org/2002/07/owl#TransitiveProperty"); public static final Resource DeprecatedProperty = m_model.createResource("http://www.w3.org/2002/07/owl#DeprecatedProperty"); public static final Resource AnnotationProperty = m_model.createResource("http://www.w3.org/2002/07/owl#AnnotationProperty"); public static final Resource Restriction = m_model.createResource("http://www.w3.org/2002/07/owl#Restriction"); public static final Resource Class = m_model.createResource("http://www.w3.org/2002/07/owl#Class"); public static final Resource OntologyProperty = m_model.createResource("http://www.w3.org/2002/07/owl#OntologyProperty"); public static final Resource ObjectProperty = m_model.createResource("http://www.w3.org/2002/07/owl#ObjectProperty"); public static final Resource FunctionalProperty = m_model.createResource("http://www.w3.org/2002/07/owl#FunctionalProperty"); public static final Resource InverseFunctionalProperty = m_model.createResource("http://www.w3.org/2002/07/owl#InverseFunctionalProperty"); public static final Resource Nothing = m_model.createResource("http://www.w3.org/2002/07/owl#Nothing"); // Vocabulary individuals /////////////////////////// }
public void testThisWillBreak() { Resource R = model.createResource(aURI); SPO.createReifiedStatement(aURI); model.add(R, RDF.subject, R); }
/** Vocabulary definitions from test-manifest.n3 */ public class TestManifest { /** The RDF model that holds the vocabulary terms */ private static final Model m_model = ModelFactory.createDefaultModel(); /** The namespace of the vocabulary as a string */ public static final String NS = "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#"; /** * The namespace of the vocabulary as a string * * @see #NS */ public static String getURI() { return NS; } /** The namespace of the vocabulary as a resource */ public static final Resource NAMESPACE = m_model.createResource(NS); /** The test statusThe expected outcome */ public static final Property result = m_model.createProperty("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result"); /** Action to perform */ public static final Property action = m_model.createProperty("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action"); /** Optional name of this entry */ public static final Property name = m_model.createProperty("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name"); /** Connects the manifest resource to rdf:type list of entries */ public static final Property entries = m_model.createProperty("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries"); /** Connects the manifest resource to rdf:type list of manifests */ public static final Property include = m_model.createProperty("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include"); /** * A type of test specifically for query evaluation testing. Query evaluation tests are required * to have an associated input dataset, a query, and an expected output dataset. */ public static final Resource QueryEvaluationTest = m_model.createResource( "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#QueryEvaluationTest"); /** * A type of test specifically for syntax testing. Syntax tests are not required to have an * associated result, only an action. Negative syntax tests are tests of which the result should * be a parser error. */ public static final Resource NegativeSyntaxTest = m_model.createResource( "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#NegativeSyntaxTest"); /** * A type of test specifically for syntax testing. Syntax tests are not required to have an * associated result, only an action. */ public static final Resource PositiveSyntaxTest = m_model.createResource( "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#PositiveSyntaxTest"); /** One entry in rdf:type list of entries */ public static final Resource ManifestEntry = m_model.createResource( "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#ManifestEntry"); /** The class of manifests */ public static final Resource Manifest = m_model.createResource("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#Manifest"); public static final Resource accepted = m_model.createResource("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#accepted"); public static final Resource proposed = m_model.createResource("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#proposed"); public static final Resource rejected = m_model.createResource("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#rejected"); }
/** * agINFRA Social visualization components aux. tool * * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { System.out.println("Hello"); // PARAMS if (args.length != 5) { System.out.println( "Proper Arguments are: [Dataset files full path] [URL store] [URI graph base] [Destination directory] [commit to 4store]"); System.out.println( "Example: java -jar xxxxx.jar /home/carlos/Desktop/agINFRA-workflow/workflow/loms/bioe/ http://localhost:81 http://laclo.laflor /home/carlos/Desktop/agINFRA-workflow/workflow/loms/bioerdf/ false"); System.exit(0); } String dspath = args[0]; String urlStore = args[1]; String uriGraph = args[2]; String destination = args[3]; String commit4store_arg = args[4]; /*String dspath = "/home/carlos/workspace/WebAPI/ds/"; String urlStore = "http://4store.ipb.ac.rs:81"; String uriGraph = "http://aginfra.eu"; String localCouchdbProxy = "localhost"; String commit4store_arg = "no";*/ boolean commit4store = false; if (commit4store_arg.equals("commit")) commit4store = true; String output = "0"; // valor de retorno String status = "ERROR"; String errorDescription = ""; String tmpMetadataFile = ""; // check if type is valid boolean bContinuar = true; // StorageService service; ArrayList<KeyValue> keyValues = new ArrayList<KeyValue>(); HashMap fileDatasetMap = new HashMap(); /* //Fetch and download IPB metadata sets. //CouchDB via PHP local proxy //http://agro.ipb.ac.rs/agcouchdb/_design/datasets/_view/list?limit=10 //http://localhost/ag_couch_proxy/proxy-IPB-datasets.php try{ System.out.println("Connecting IPB CouchDB..."); String url = "http://"+localCouchdbProxy+"/ag_couch_proxy/proxy-IPB-datasets.php?dspath="+dspath; WebResource webResource = Client.create().resource(url); //System.out.println(url); ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON,MediaType.TEXT_HTML,MediaType.WILDCARD).get(ClientResponse.class); if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } //String response_str = response.getEntity(String.class); //I don't know why this does not work when running in shell String response_str = getStringFromInputStream(response.getEntityInputStream()); //System.out.println(response_str); //debug System.out.println("Finished IPB call"); System.out.println("Reading Dataset Map..."); //READ CSV //create BufferedReader to read csv file StringTokenizer st = null; int lineNumber = 0, tokenNumber = 0; //read comma separated file line by line Scanner scanner = new Scanner(response_str); while (scanner.hasNextLine()) { lineNumber++; String strLine = scanner.nextLine(); //break comma separated line using "," st = new StringTokenizer(strLine, ","); String datasetFile = ""; String datasetName = ""; while(st.hasMoreTokens()) { //display csv values tokenNumber++; //System.out.println("Line # " + lineNumber +", Token # " + tokenNumber + ", Token : "+ st.nextToken()); if(tokenNumber == 1) datasetFile = st.nextToken(); if(tokenNumber == 2) datasetName = st.nextToken(); } fileDatasetMap.put(datasetFile,datasetName); //reset token number tokenNumber = 0; } System.out.println("Finished Map reading"); } catch (Exception e) { e.printStackTrace(); } */ /* //foreach dataset.tar.gz ** //Iterate File root = new File("ds/"); Collection files = FileUtils.listFiles(root, null, false); //mini db processed files ArrayList processed = new ArrayList(); try { BufferedReader br = new BufferedReader(new FileReader("processed.txt")); String line; while((line = br.readLine()) != null) { processed.add(line); } } catch (IOException e) { e.printStackTrace(); } System.out.println("Iterating all downloaded datasets tgz files..."); int dsCount = 0; for (Iterator iterator = files.iterator(); iterator.hasNext();) { File dsFile = (File) iterator.next(); String inputDataset = dsFile.getAbsolutePath(); dsCount = dsCount + 1; System.out.println(" Processing "+dsCount+":"+inputDataset); //debug //po5i: mini db processed files if(processed.contains(inputDataset)){ System.out.println(" >>Already processed... skipping... "); continue; } else { processed.add(inputDataset); try { FileWriter fileWritter = new FileWriter("processed.txt",true); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); bufferWritter.write(inputDataset+"\n"); bufferWritter.close(); } catch (IOException e) { e.printStackTrace(); } } //Set the GraphID String graphID = (String) fileDatasetMap.get(dsFile.getName()); System.out.println(" Graph:: "+graphID); //Uncompress the dataset and iterate throughout the files try { FileInputStream fin = new FileInputStream(inputDataset); BufferedInputStream in = new BufferedInputStream(fin); FileOutputStream out = new FileOutputStream("ds/archive.tar"); GzipCompressorInputStream gzIn; gzIn = new GzipCompressorInputStream(in); final byte[] buffer = new byte[1024]; int n = 0; while (-1 != (n = gzIn.read(buffer))) { out.write(buffer, 0, n); } out.close(); gzIn.close(); //read the tar File input = new File("ds/archive.tar"); //getFile("ds/archive.tar"); InputStream is = new FileInputStream(input); ArchiveInputStream in1 = new ArchiveStreamFactory().createArchiveInputStream("tar", is); TarArchiveEntry entry = (TarArchiveEntry)in1.getNextEntry(); while (entry != null) {// create a file with the same name as the tarEntry File destPath = new File("ds/extract/" + entry.getName()); if (entry.isDirectory()) { destPath.mkdirs(); } else { destPath.createNewFile(); OutputStream out1 = new FileOutputStream(destPath); IOUtils.copy(in1, out1); out1.close(); } entry = (TarArchiveEntry)in1.getNextEntry(); } in1.close(); } catch (Exception e) { e.printStackTrace(); }*/ // Iterate on extracted files try { File root1 = new File(dspath); Collection files1 = FileUtils.listFiles(root1, null, true); // new File(dspath+"../rdf").mkdir(); for (Iterator iterator1 = files1.iterator(); iterator1.hasNext(); ) { File lomFile = (File) iterator1.next(); String inputFile = lomFile.getAbsolutePath(); // System.out.println(" Processing:"+inputFile); //debug if (bContinuar) { // save metadata stream in a local file tmpMetadataFile = inputFile; String valid = "1"; // valid = XMLValidator.validate(tmpMetadataFile, // StorageService.getXSDFile(storageType)); boolean hasSource = false; if (tmpMetadataFile.length() > 0) { // TODO: metadata validation // valid = "1"; if (valid.equalsIgnoreCase("1")) { // generate id for the new material // output = graphID; // save metatada in rdf // obtain key-value pairs try { LOMParser.parseToKeyValue(tmpMetadataFile); if (!LOMParser.keyValues.isEmpty()) { keyValues = LOMParser.keyValues; } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } if (!keyValues.isEmpty()) { int canSave = 1; if (canSave > 0) { // 4store // save to rdf this triple (slow) // HandleGraph graph = new HandleGraph(urlStore,uriGraph); // result = graph.AppendTriple(graphID, keyValues); // 4store // prepare RDF file (better) try { // HELP: http://www.roseindia.net/tutorials/rdf/generateRDF.shtml Model model = ModelFactory.createDefaultModel(); for (KeyValue kv : keyValues) { String s = uriGraph + "/" + lomFile.getName(); // String p = URLEncoder.encode(kv.getKey(),"UTF-8"); String p = kv.getKey().replaceAll("[^\\w\\s\\.]", "_"); String v = kv.getValue(); // obtener el autor del CDATA en variable v if (v.contains("CDATA")) { v = v.replace("<![CDATA[", ""); v = v.replace("]]>", ""); VCardEngine vcardEngine = new VCardEngine(); VCard vcard = vcardEngine.parse(v); if (vcard.hasFN()) v = vcard.getFN().getFormattedName(); else if (vcard.hasN()) v = vcard.getN().getFamilyName(); else { // format string it can be parsed. StringBuffer sb; sb = new StringBuffer(v); sb.insert(v.indexOf("VERSION:"), "\n"); v = sb.toString(); sb = new StringBuffer(v); sb.insert(v.indexOf(" FN:") + 1, "\n"); v = sb.toString(); sb = new StringBuffer(v); sb.insert(v.indexOf(" N:") + 1, "\n"); v = sb.toString(); sb = new StringBuffer(v); sb.insert(v.indexOf("ORG:"), "\n"); v = sb.toString(); sb = new StringBuffer(v); sb.insert(v.indexOf("EMAIL:"), "\n"); v = sb.toString(); sb = new StringBuffer(v); sb.insert(v.indexOf("END:"), "\n"); v = sb.toString(); vcard = vcardEngine.parse(v); if (vcard.hasFN()) v = vcard.getFN().getFormattedName(); else if (vcard.hasN()) v = vcard.getN().getFamilyName(); else { System.out.println(" ~ ~ Problem with:::" + v); System.out.println(" ~ ~ When Processing:" + inputFile); // debug } // System.out.println(" ~ author is: "+v); } } // System.out.println("p: "+p+"\t\t\t v: "+v); Property lom_prop = model.createProperty("http://ltsc.ieee.org/xsd/LOM#" + p); Resource node = model.createResource(s).addProperty(lom_prop, v); } FileOutputStream fop = null; File rdfFile = new File(destination + lomFile.getName().replace(".xml", ".rdf")); fop = new FileOutputStream(rdfFile); // model.write(System.out); model.write(fop); // 4store if (commit4store) { HandleGraph graph = new HandleGraph(urlStore, uriGraph); int result = graph.AppendGraph(rdfFile.getAbsolutePath()); // returns 0-1 } } catch (Exception e) { e.printStackTrace(); } // break; //debug } output = "1"; } else { output = "0"; errorDescription = "Could not handle metadata to key-value"; } } else { errorDescription = "XML Validation:" + valid; } } else { errorDescription = "Could not handle metadata file"; } } } } catch (Exception e) { e.printStackTrace(); } /*//break; //debug //Borrar todo lo de ds/extract/, rdf y el archive.tar para liberar espacio try { FileUtils.deleteDirectory(new File("ds/extract/")); FileUtils.deleteDirectory(new File("ds/rdf/")); FileUtils.deleteQuietly(new File("ds/archive.tar")); } catch (IOException e) { e.printStackTrace(); } } */ // prepare response if (output.contentEquals("0")) status = "ERROR: " + errorDescription; else status = "OK"; System.out.println(status); }
public void testConversion() { final String uri = "spoo:handle"; model.createReifiedStatement(uri, SPO); ReifiedStatement rs2 = (ReifiedStatement) model.createResource(uri).as(ReifiedStatement.class); assertEquals("recover statement", SPO, rs2.getStatement()); }
public void testDoesNotReifyUnknown() { testDoesNotReify("model should not reify rubbish", model.createResource("spoo:rubbish")); }
public void testDoesNotReifyElsewhere() { final String uri = "spoo:rubbish"; Model m2 = getModel(); model.createReifiedStatement(uri, SPO); testDoesNotReify("blue model should not reify rubbish", m2.createResource(uri)); }
/** Vocabulary definitions from vocabularies/dublin-core_types.xml */ public class DCTypes { /** The RDF model that holds the vocabulary terms */ private static final Model m_model = ModelFactory.createDefaultModel(); /** The namespace of the vocabulary as a string */ public static final String NS = "http://purl.org/dc/dcmitype/"; /** * The namespace of the vocabulary as a string * * @see #NS */ public static String getURI() { return NS; } /** The namespace of the vocabulary as a resource */ public static final Resource NAMESPACE = m_model.createResource(NS); /** An aggregation of resources. */ public static final Resource Collection = m_model.createResource("http://purl.org/dc/dcmitype/Collection"); /** Data encoded in a defined structure. */ public static final Resource Dataset = m_model.createResource("http://purl.org/dc/dcmitype/Dataset"); /** A non-persistent, time-based occurrence. */ public static final Resource Event = m_model.createResource("http://purl.org/dc/dcmitype/Event"); /** A visual representation other than text. */ public static final Resource Image = m_model.createResource("http://purl.org/dc/dcmitype/Image"); /** A resource requiring interaction from the user to be understood, executed, or experienced. */ public static final Resource InteractiveResource = m_model.createResource("http://purl.org/dc/dcmitype/InteractiveResource"); /** * A series of visual representations imparting an impression of motion when shown in succession. */ public static final Resource MovingImage = m_model.createResource("http://purl.org/dc/dcmitype/MovingImage"); /** An inanimate, three-dimensional object or substance. */ public static final Resource PhysicalObject = m_model.createResource("http://purl.org/dc/dcmitype/PhysicalObject"); /** A system that provides one or more functions. */ public static final Resource Service = m_model.createResource("http://purl.org/dc/dcmitype/Service"); /** A computer program in source or compiled form. */ public static final Resource Software = m_model.createResource("http://purl.org/dc/dcmitype/Software"); /** A resource primarily intended to be heard. */ public static final Resource Sound = m_model.createResource("http://purl.org/dc/dcmitype/Sound"); /** A static visual representation. */ public static final Resource StillImage = m_model.createResource("http://purl.org/dc/dcmitype/StillImage"); /** A resource consisting primarily of words for reading. */ public static final Resource Text = m_model.createResource("http://purl.org/dc/dcmitype/Text"); }
/** * Vocabulary definitions from file:doc/terms/d2rq.ttl * * @author Auto-generated by schemagen on 02 Apr 2012 20:51 */ public class D2RQ { /** The RDF model that holds the vocabulary terms */ private static Model m_model = ModelFactory.createDefaultModel(); /** The namespace of the vocabulary as a string */ public static final String NS = "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#"; /** * The namespace of the vocabulary as a string * * @see #NS */ public static String getURI() { return NS; } /** The namespace of the vocabulary as a resource */ public static final Resource NAMESPACE = m_model.createResource(NS); /** An additional property to be served for all associated class definitions */ public static final Property additionalClassDefinitionProperty = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#additionalClassDefinitionProperty"); public static final Property additionalProperty = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#additionalProperty"); /** An additional property to be served for all associated property definitions */ public static final Property additionalPropertyDefinitionProperty = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#additionalPropertyDefinitionProperty"); /** TABLE AS ALIAS declaration for establishing an alternate table name. */ public static final Property alias = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#alias"); /** * Value: true/false that describe the databases ability to handle DISTINCT correctly. Deprecated, * the engine now determines this automatically. */ public static final Property allowDistinct = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#allowDistinct"); /** Comma-separated list of database columns used for construction of blank nodes. */ public static final Property bNodeIdColumns = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#bNodeIdColumns"); public static final Property belongsToClassMap = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#belongsToClassMap"); /** Name of a column of a binary type, such as BINARY, VARBINARY or BLOB. */ public static final Property binaryColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#binaryColumn"); /** Name of a column of type BIT. */ public static final Property bitColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#bitColumn"); /** Name of a column of type BOOLEAN. */ public static final Property booleanColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#booleanColumn"); /** Links d2rq:classMaps to RDFS or OWL classes. */ public static final Property class_ = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#class"); /** A comment to be served as rdfs:comment for all associated class definitions */ public static final Property classDefinitionComment = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#classDefinitionComment"); /** A label to be served as rdfs:label for all associated class definitions */ public static final Property classDefinitionLabel = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#classDefinitionLabel"); /** * Used to link RDFS or OWL classes to d2r:classMaps. Deprecated, use inverse d2rq:class instead. */ public static final Property classMap = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#classMap"); public static final Property column = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#column"); /** SQL WHERE condition that must be satisfied for a database row to be mapped. */ public static final Property condition = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#condition"); /** * A constant RDF node to be used as the value of this property bridge, or as the resource of a * singleton class map. */ public static final Property constantValue = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#constantValue"); /** * Set to true if the table, after applying d2rq:joins and d2rq:conditions, may contain duplicate * records. */ public static final Property containsDuplicates = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#containsDuplicates"); /** A database column containing data to be made downloadable. */ public static final Property contentDownloadColumn = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#contentDownloadColumn"); public static final Property dataStorage = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#dataStorage"); public static final Property databaseValue = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#databaseValue"); /** The datatype of literals created by this bridge. */ public static final Property datatype = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#datatype"); /** Name of a column of type DATE. */ public static final Property dateColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#dateColumn"); /** Links a d2rq:PropertyBridge to a dynamic property. */ public static final Property dynamicProperty = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#dynamicProperty"); /** The number of rows that should be fetched from the database at once */ public static final Property fetchSize = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#fetchSize"); /** Link to a translation table in an external CSV file. */ public static final Property href = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#href"); /** Name of a column of type INTERVAL. */ public static final Property intervalColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#intervalColumn"); /** * Qualified name of a Java class that implements de.fuberlin.wiwiss.d2rq.Translator and * translates between database and RDF. */ public static final Property javaClass = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#javaClass"); /** JDBC data source name. Deprecated, use d2rq:jdbcURL instead. */ public static final Property jdbcDSN = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#jdbcDSN"); public static final Property jdbcDriver = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#jdbcDriver"); /** JDBC connection URL. */ public static final Property jdbcURL = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#jdbcURL"); /** SQL join condition over tables in the database. */ public static final Property join = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#join"); /** The language tag of literals created by this bridge. */ public static final Property lang = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#lang"); /** The number of results to retrieve from the database for this PropertyBridge */ public static final Property limit = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#limit"); /** * The number of results to retrieve from the database for the inverse statements for this * PropertyBridge */ public static final Property limitInverse = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#limitInverse"); /** URL of a D2RQ mapping file. */ public static final Property mappingFile = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#mappingFile"); /** * The Internet media type, such as image/png, of the downloadable content, suitable for use in * the HTTP Content-Type header. */ public static final Property mediaType = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#mediaType"); /** Name of a column of a numeric type, such as INT or DOUBLE or DECIMAL. */ public static final Property numericColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#numericColumn"); /** ODBC DSN */ public static final Property odbcDSN = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#odbcDSN"); /** The column after which to sort results in ascending order for this PropertyBridge */ public static final Property orderAsc = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#orderAsc"); /** The column after which to sort results in descending order for this PropertyBridge */ public static final Property orderDesc = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#orderDesc"); public static final Property password = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#password"); public static final Property pattern = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#pattern"); /** Links a d2rq:PropertyBridge to an RDF property. */ public static final Property property = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#property"); /** * Used for linking RDFS properties to D2R property bridges. Deprecated, use inverse d2rq:property * instead. */ public static final Property propertyBridge = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#propertyBridge"); /** A comment to be served as rdfs:comment for all associated properties */ public static final Property propertyDefinitionComment = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#propertyDefinitionComment"); /** A label to be served as rdfs:label for all associated properties */ public static final Property propertyDefinitionLabel = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#propertyDefinitionLabel"); public static final Property propertyName = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#propertyName"); public static final Property propertyValue = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#propertyValue"); public static final Property rdfValue = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#rdfValue"); /** Has to be used if a join refers to a different classMap. */ public static final Property refersToClassMap = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#refersToClassMap"); /** Base URI for resources generated by relative URI patterns. */ public static final Property resourceBaseURI = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#resourceBaseURI"); /** Enforced upper limit for the size of SQL result sets. */ public static final Property resultSizeLimit = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#resultSizeLimit"); /** Whether to serve inferred and user-supplied vocabulary data */ public static final Property serveVocabulary = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#serveVocabulary"); /** A SQL expression whose result will be the value of this property bridge. */ public static final Property sqlExpression = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#sqlExpression"); /** URL of a SQL script that will be run on startup. */ public static final Property startupSQLScript = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#startupSQLScript"); /** Name of a column of a character type, such as CHAR, VARCHAR, NVARCHAR or CLOB. */ public static final Property textColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#textColumn"); /** Name of a column of type TIME. */ public static final Property timeColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#timeColumn"); /** Name of a column of type TIMESTAMP. */ public static final Property timestampColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#timestampColumn"); public static final Property translateWith = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#translateWith"); public static final Property translation = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#translation"); /** Database column which contains URIs. */ public static final Property uriColumn = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#uriColumn"); /** URI pattern with placeholders that will be filled with values from a database column. */ public static final Property uriPattern = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#uriPattern"); /** An SQL expression whose result will be the URI value of this property bridge. */ public static final Property uriSqlExpression = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#uriSqlExpression"); /** Whether to use bleeding edge optimizations */ public static final Property useAllOptimizations = m_model.createProperty( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#useAllOptimizations"); public static final Property username = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#username"); /** Optimizing hint: a string contained in every value of this resource map. */ public static final Property valueContains = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#valueContains"); /** Optimizing hint: the maximum length of values of this resource map. */ public static final Property valueMaxLength = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#valueMaxLength"); /** Optimizing hint: a regular expression matching every value of this resource map. */ public static final Property valueRegex = m_model.createProperty("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#valueRegex"); /** * Represents an additional property that may be added to instances as well as class and property * definitions. */ public static final Resource AdditionalProperty = m_model.createResource( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#AdditionalProperty"); /** Maps an RDFS or OWL class to its database representation. */ public static final Resource ClassMap = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#ClassMap"); /** Represents general settings. */ public static final Resource Configuration = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#Configuration"); /** Jena Assemler specification for a relational database, mapped to RDF using the D2RQ tool. */ public static final Resource D2RQModel = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#D2RQModel"); /** Represents a database. */ public static final Resource Database = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#Database"); /** (Deprecated) Maps a datatype property to one or more database columns. */ public static final Resource DatatypePropertyBridge = m_model.createResource( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#DatatypePropertyBridge"); /** Makes the contents of some database column downloadable. */ public static final Resource DownloadMap = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#DownloadMap"); /** (Deprecated) Maps an object property to one or more database columns. */ public static final Resource ObjectPropertyBridge = m_model.createResource( "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#ObjectPropertyBridge"); /** Maps an RDF property to one or more database columns. */ public static final Resource PropertyBridge = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#PropertyBridge"); /** * A database-to-RDF mapping from one or more database columns to a set of RDF resources. An * abstract class, usually not used directly. */ public static final Resource ResourceMap = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#ResourceMap"); /** Translation Key/Value Pair. */ public static final Resource Translation = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#Translation"); /** Lookup table for translations used in the mapping process. */ public static final Resource TranslationTable = m_model.createResource("http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#TranslationTable"); }