RDFList list = model.createList(new RDFNode[] {}); //string with names of rdf classes String[] parts = list.split("-"); for(int i = 0; i<parts.length; i++){ OntClass oclass = model.getOntClass("http://example.org/"+parts[i]); list = list.with(oclass); }
@Override public SecuredRDFList with(final RDFNode value) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(SecurityEvaluator.FUTURE, listFirst().asNode(), value.asNode())); return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem() .with(value)); } }
public static void normalizeSqcfModel(Model testSuitesModel) { // Transform hasTest to an RDF list Property hasTest = ResourceFactory.createProperty("http://sqc-framework.aksw.org/testsuite#hasTest"); List<Statement> stmts = testSuitesModel.listStatements(null, hasTest, (RDFNode)null).toList(); testSuitesModel.remove(stmts); Model tmpModel = ModelFactory.createDefaultModel(); tmpModel.add(stmts); Set<Resource> suites = stmts.stream().map(Statement::getSubject).collect(Collectors.toSet()); for(Resource suite : suites) { RDFList list = suite.getModel().createList(); List<RDFNode> testCases = tmpModel.listObjectsOfProperty(suite, hasTest).toList(); for(RDFNode testCase : testCases) { list = list.with(testCase); } suite.addProperty(SparqlQcVocab.hasTest, list); } renameProperty(testSuitesModel, ResourceFactory.createProperty("http://sqc-framework.aksw.org/vocab#result"), SparqlQcVocab.result.getURI()); renameProperty(testSuitesModel, ResourceFactory.createProperty("http://sqc-framework.aksw.org/vocab#subQuery"), SparqlQcVocab.sourceQuery.getURI()); renameProperty(testSuitesModel, ResourceFactory.createProperty("http://sqc-framework.aksw.org/vocab#superQuery"), SparqlQcVocab.targetQuery.getURI()); //RDFDataMgr.write(System.out, testSuitesModel, RDFFormat.TURTLE_PRETTY); }
public static void normalizeSqcfModel(Model testSuitesModel) { // Transform hasTest to an RDF list Property hasTest = ResourceFactory.createProperty("http://sqc-framework.aksw.org/testsuite#hasTest"); List<Statement> stmts = testSuitesModel.listStatements(null, hasTest, (RDFNode)null).toList(); testSuitesModel.remove(stmts); Model tmpModel = ModelFactory.createDefaultModel(); tmpModel.add(stmts); Set<Resource> suites = stmts.stream().map(Statement::getSubject).collect(Collectors.toSet()); for(Resource suite : suites) { RDFList list = suite.getModel().createList(); List<RDFNode> testCases = tmpModel.listObjectsOfProperty(suite, hasTest).toList(); for(RDFNode testCase : testCases) { list = list.with(testCase); } suite.addProperty(SparqlQcVocab.hasTest, list); } renameProperty(testSuitesModel, ResourceFactory.createProperty("http://sqc-framework.aksw.org/vocab#result"), SparqlQcVocab.result.getURI()); renameProperty(testSuitesModel, ResourceFactory.createProperty("http://sqc-framework.aksw.org/vocab#subQuery"), SparqlQcVocab.sourceQuery.getURI()); renameProperty(testSuitesModel, ResourceFactory.createProperty("http://sqc-framework.aksw.org/vocab#superQuery"), SparqlQcVocab.targetQuery.getURI()); //RDFDataMgr.write(System.out, testSuitesModel, RDFFormat.TURTLE_PRETTY); }
/** Add the given value to a list which is the value of the given property */ protected void addListPropertyValue( Property p, String name, RDFNode value ) { checkProfile( p, name ); // get the list value if (hasProperty( p )) { RDFNode cur = getRequiredProperty( p ).getObject(); if (!cur.canAs( RDFList.class )) { throw new OntologyException( "Tried to add a value to a list-valued property " + p + " but the current value is not a list: " + cur ); } RDFList values = cur.as( RDFList.class ); // now add our value to the list if (!values.contains( value )){ RDFList newValues = values.with( value ); // if the previous values was nil, the return value will be a new list if (newValues != values) { removeAll( p ); addProperty( p, newValues ); } } } else { // create a new list to hold the only value we know so far addProperty( p, ((OntModel) getModel()).createList( new RDFNode[] {value} ) ); } }
/** Add the given value to a list which is the value of the given property */ protected void addListPropertyValue( Property p, String name, RDFNode value ) { checkProfile( p, name ); // get the list value if (hasProperty( p )) { RDFNode cur = getRequiredProperty( p ).getObject(); if (!cur.canAs( RDFList.class )) { throw new OntologyException( "Tried to add a value to a list-valued property " + p + " but the current value is not a list: " + cur ); } RDFList values = cur.as( RDFList.class ); // now add our value to the list if (!values.contains( value )){ RDFList newValues = values.with( value ); // if the previous values was nil, the return value will be a new list if (newValues != values) { removeAll( p ); addProperty( p, newValues ); } } } else { // create a new list to hold the only value we know so far addProperty( p, ((OntModel) getModel()).createList( new RDFNode[] {value} ) ); } }
public void testAdd() { final Resource root = model.createResource(TestList.NS + "root"); final Property p = model.createProperty(TestList.NS, "p"); final Resource nil = model.getResource(RDF.nil.getURI()); RDFList list = nil.as(RDFList.class); final Resource[] toAdd = new Resource[] { model.createResource(TestList.NS + "a"), model.createResource(TestList.NS + "b"), model.createResource(TestList.NS + "c"), model.createResource(TestList.NS + "d"), model.createResource(TestList.NS + "e"), }; // add each of these resources onto the end of the list for (final Resource element : toAdd) { final RDFList list0 = list.with(element); checkValid("addTest0", list0, true); Assert.assertTrue("added'ed lists should be equal", list.equals(nil) || list0.equals(list)); list = list0; } // relate the root to the list model.add(root, p, list); // should be isomorphic with list 5 final Model m0 = ModelFactory.createDefaultModel(); m0.read( getFileName( "ontology/list5.rdf")); Assert.assertTrue("Add'ed and read models should be the same", m0.isIsomorphicWith(model)); }
public void testAdd() { final Resource root = model.createResource(TestList.NS + "root"); final Property p = model.createProperty(TestList.NS, "p"); final Resource nil = model.getResource(RDF.nil.getURI()); RDFList list = nil.as(RDFList.class); final Resource[] toAdd = new Resource[] { model.createResource(TestList.NS + "a"), model.createResource(TestList.NS + "b"), model.createResource(TestList.NS + "c"), model.createResource(TestList.NS + "d"), model.createResource(TestList.NS + "e"), }; // add each of these resources onto the end of the list for (final Resource element : toAdd) { final RDFList list0 = list.with(element); checkValid("addTest0", list0, true); Assert.assertTrue("added'ed lists should be equal", list.equals(nil) || list0.equals(list)); list = list0; } // relate the root to the list model.add(root, p, list); // should be isomorphic with list 5 final Model m0 = ModelFactory.createDefaultModel(); m0.read( getFileName( "ontology/list5.rdf")); Assert.assertTrue("Add'ed and read models should be the same", m0.isIsomorphicWith(model)); }