.flatMap(m -> m.listObjectsOfProperty(OWL.imports).toList().stream()) .filter(RDFNode::isResource) .map(RDFNode::asResource)
@Override public Geometry read(Model model, Resource base) { List<RDFNode> xlongs = model.listObjectsOfProperty(base, GEO.xlong).toList(); List<RDFNode> lats = model.listObjectsOfProperty(base, GEO.lat).toList(); Point result; if(xlongs.isEmpty() && lats.isEmpty()) { result = null; } else if(xlongs.size() == 1 && lats.size() == 1) { RDFNode xlong = xlongs.get(0); RDFNode lat = lats.get(0); Object ox = xlong.asLiteral().getValue(); Object oy = lat.asLiteral().getValue(); double x = extractDouble(ox); double y = extractDouble(oy); result = geometryFactory.createPoint(new Coordinate(x, y)); } else { // Invalid geometry // TODO Add support for an error callback result = null; } return result; } }
public static Set<String> getObservationDates(String datasetPLD) { logger.info("[Quality Metadata] - Getting Observation Dates for {}", datasetPLD); String graphName = graphs.get(StringUtils.strippedURI(datasetPLD)); Model qualityMetadata = ModelFactory.createDefaultModel(); qualityMetadata.add(d.getNamedModel(graphName)); qualityMetadata.add(InternalModelConf.getFlatModel()); Set<String> dates = new HashSet<String>(); List<RDFNode> list = qualityMetadata.listObjectsOfProperty(SDMXDIMENSION.timePeriod).toList(); list.forEach(res -> { String ldDate = res.asLiteral().getValue().toString(); String jsonDate = null; try { jsonDate = StringUtils.toJSONDateFormat(ldDate); } catch (ParseException e) { ExceptionOutput.output(e, "[Dataset Profiling] Cannot convert Linked Data date fromat to JSON date format for "+ ldDate, logger); } if (jsonDate != null) dates.add("\""+jsonDate+"\""); }); return dates; }
private String tryPropertyForPreferredLanguages( OntResource r, Property p, boolean alsoTryNoLang ) { String label = null; List<RDFNode> labels = (List<RDFNode>) r.listPropertyValues(p).toList(); String lang = "en-US"; label = getLabel2(lang,labels); if ( label == null && alsoTryNoLang ) { label = getLabel2("", labels); } return label; }
for(RDFNode targetNode : shape.getModel().listObjectsOfProperty(shape, SH.targetNode).toList()) { results.add(targetNode.inModel(dataModel));
for(RDFNode targetNode : shape.getModel().listObjectsOfProperty(shape, SH.targetNode).toList()) { results.add(targetNode.inModel(dataModel));
if(ni.hasNext()) String coordinationMessageUri = ni.toList().get(0).asResource().getURI().toString(); if(coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_ABORT.getURI().toString())) logger.debug("Sent COORDINATION_MESSAGE: {}", coordinationMessageUri);
@Override protected void doRun(Event event, EventListener executingListener) throws Exception { //If we receive a close event, it must carry a commit message. if(event instanceof CloseFromOtherNeedEvent) { URI needURI = ((CloseFromOtherNeedEvent) event).getNeedURI(); WonMessage wonMessage = ((CloseFromOtherNeedEvent) event).getWonMessage(); NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator( wonMessage.getMessageContent(), new RdfUtils.ModelVisitor<NodeIterator>() { @Override public NodeIterator visit(final Model model) { return model.listObjectsOfProperty( model.createProperty(WON_TX.COORDINATION_MESSAGE.getURI())); } }); assert ni.hasNext() : "no additional content found in close message, expected a commit"; String coordinationMessageUri = ni.toList().get(0).asResource().getURI().toString(); assert coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_COMMIT.getURI().toString()) : "expected a " + "Commmit message"; getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(needURI)); getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(needURI)); } }
@Test public void testListObjects() { secEval.setPrincipal("darla"); /* * darla can only add values to msg4 ex:msg4 rdf:type ex:msg; ex:to * "darla" ; ex:from "bob" ; ex:subj "bob to darla 1" */ Assert.assertTrue(baseModel.listObjects().toList().size() > 4); Assert.assertEquals(4, securedModel.listObjects().toList().size()); Assert.assertTrue(baseModel.listObjectsOfProperty(pFrom).toList() .size() > 1); Assert.assertEquals(1, securedModel.listObjectsOfProperty(pFrom) .toList().size()); Resource s = ResourceFactory.createResource(String.format(NS_FMT, "msg3")); Assert.assertEquals(1, baseModel.listObjectsOfProperty(s, pFrom) .toList().size()); Assert.assertEquals(0, securedModel.listObjectsOfProperty(s, pFrom) .toList().size()); s = ResourceFactory.createResource(String.format(NS_FMT, "msg4")); Assert.assertEquals(1, baseModel.listObjectsOfProperty(s, pFrom) .toList().size()); Assert.assertEquals(1, securedModel.listObjectsOfProperty(s, pFrom) .toList().size()); }
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 ActionResult handleAction(Individual actionInd) { if (instanceOf(actionInd,WorkflowOntology.SPARQLCONSTRUCTAction)) { OntModel sourceModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); for (RDFNode node : (List<RDFNode>) actionInd.listPropertyValues(WorkflowOntology.sourceModel).toList()) { log.debug("SPARQL: adding submodel "); sourceModel.addSubModel(getModel(node)); } if (actionInd.getPropertyValue(WorkflowOntology.destinationModel) == null) { log.debug("Error: destination model for SPARQL Construct action not specified for this action"); return null; } Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); Model tempModel = ModelFactory.createDefaultModel(); OntResource sparqlQuery = (OntResource) actionInd.getPropertyValue(WorkflowOntology.sparqlQuery); String queryStr = ((Literal)sparqlQuery.getPropertyValue(ResourceFactory.createProperty(QUERY_STR_PROPERTY))).getLexicalForm(); log.debug("SPARQL query: \n" + queryStr); Query query = QueryFactory.create(queryStr,Syntax.syntaxARQ); QueryExecution qexec = QueryExecutionFactory.create(query,sourceModel); qexec.execConstruct(tempModel); destinationModel.add(tempModel); return new ActionResultImpl(); } return null; } }
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 ActionResult handleAction(Individual actionInd) { if (instanceOf(actionInd,WorkflowOntology.NameBlankNodesAction)) { OntModel sourceModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); for (RDFNode node : (List<RDFNode>) actionInd.listPropertyValues(WorkflowOntology.sourceModel).toList()) { sourceModel.addSubModel(getModel(node)); } Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); String uriPrefix = getValue(actionInd.getPropertyValue(WorkflowOntology.uriPrefix)).getLexicalForm(); destinationModel.add(utils.renameBNodes(sourceModel, uriPrefix)); return new ActionResultImpl(); } return null; } }
public void testSeqAddInts() { final int num = 10; final Seq seq = model.createSeq(); for (int i = 0; i < num; i += 1) { seq.add(i); } Assert.assertEquals(num, seq.size()); final List<RDFNode> L = seq.iterator().toList(); Assert.assertEquals(num, L.size()); for (int i = 0; i < num; i += 1) { Assert.assertEquals(i, ((Literal) L.get(i)).getInt()); } }
public void testSeqAddInts() { final int num = 10; final Seq seq = model.createSeq(); for (int i = 0; i < num; i += 1) { seq.add(i); } Assert.assertEquals(num, seq.size()); final List<RDFNode> L = seq.iterator().toList(); Assert.assertEquals(num, L.size()); for (int i = 0; i < num; i += 1) { Assert.assertEquals(i, ((Literal) L.get(i)).getInt()); } }
@Test public void testDifferentFromInBody() { final OntModel ontModel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, null); ontModel.read(_base + "sibling-rule.n3", "TTL"); final Resource alice = ontModel.createResource("family:alice"); final Property sibling = ontModel.createProperty("family:sibling"); final Resource bob = ontModel.createResource("family:bob"); assertTrue(ontModel.contains(alice, sibling, bob)); assertTrue(ontModel.contains(bob, sibling, alice)); assertEquals(Collections.singletonList(bob), ontModel.listObjectsOfProperty(alice, sibling).toList()); assertEquals(Collections.singletonList(alice), ontModel.listObjectsOfProperty(bob, sibling).toList()); }
protected void testRemove( final boolean[] retain ) { final int num = retain.length; final Seq seq = model.createSeq(); for (int i = 0; i < num; i += 1) { seq.add(i); } // final List<RDFNode> retained = new ArrayList<>(); // final NodeIterator nIter = seq.iterator(); for ( boolean aRetain : retain ) { final RDFNode x = nIter.nextNode(); if ( aRetain ) { retained.add( x ); } else { nIter.remove(); } } // Assert.assertFalse(nIter.hasNext()); Assert.assertEquals(retained, seq.iterator().toList()); }
public ActionResult handleAction(Individual actionInd) { if (instanceOf(actionInd,WorkflowOntology.SmushResourcesAction)) { OntModel sourceModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); for (RDFNode node : (List<RDFNode>) actionInd.listPropertyValues(WorkflowOntology.sourceModel).toList()) { sourceModel.addSubModel(getModel(node)); } Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); String smushPropertyURI = getValue(actionInd.getPropertyValue(WorkflowOntology.smushOnProperty)).getLexicalForm(); destinationModel.enterCriticalSection(Lock.WRITE); try { destinationModel.add(utils.smushResources(sourceModel, ResourceFactory.createProperty(smushPropertyURI))); } finally { destinationModel.leaveCriticalSection(); } return new ActionResultImpl(); } return null; } }
protected void testRemove( final boolean[] retain ) { final int num = retain.length; final Seq seq = model.createSeq(); for (int i = 0; i < num; i += 1) { seq.add(i); } // final List<RDFNode> retained = new ArrayList<>(); // final NodeIterator nIter = seq.iterator(); for ( boolean aRetain : retain ) { final RDFNode x = nIter.nextNode(); if ( aRetain ) { retained.add( x ); } else { nIter.remove(); } } // Assert.assertFalse(nIter.hasNext()); Assert.assertEquals(retained, seq.iterator().toList()); }
public ActionResult handleAction(Individual actionInd) { if (instanceOf(actionInd,WorkflowOntology.SplitPropertyValuesAction)) { // We use an OntModel here because this API supports submodels OntModel sourceModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); for (RDFNode node : (List<RDFNode>) actionInd.listPropertyValues(WorkflowOntology.sourceModel).toList()) { sourceModel.addSubModel(getModel(node)); } Model destinationModel = getModel(actionInd.getPropertyValue(WorkflowOntology.destinationModel)); String propertyURI = getValue(actionInd.getPropertyValue(WorkflowOntology.originalProperty)).getLexicalForm(); String newPropertyURI = getValue(actionInd.getPropertyValue(WorkflowOntology.newProperty)).getLexicalForm(); String splitRegex = getValue(actionInd.getPropertyValue(WorkflowOntology.splitRegex)).getLexicalForm(); boolean trim = true; try { trim = getValue(actionInd.getPropertyValue(WorkflowOntology.trim)).getBoolean(); } catch (Exception e) {} destinationModel.enterCriticalSection(Lock.WRITE); try { destinationModel.add(utils.splitPropertyValues(sourceModel, propertyURI, splitRegex, newPropertyURI, trim)); } finally { destinationModel.leaveCriticalSection(); } return new ActionResultImpl(); } else { return null; } } }