private Statement normaliseLiterals(Statement s) { RDFNode O = s.getObject(); if (O.isLiteral()) if (XSD.xstring.getURI().equals(O.asNode().getLiteralDatatypeURI())) { Model M = s.getModel(); Resource S = s.getSubject(); Property P = s.getPredicate(); return M.createStatement(S, P, O.asNode().getLiteralLexicalForm()); } return s; } }
private void createGraphNodeToTriplesNodeMap(KR2RMLMapping kr2rmlMapping) throws FileNotFoundException, UnsupportedEncodingException{ StmtIterator itr = model.listStatements(null, model.getProperty(Uris.KM_NODE_ID_URI), (RDFNode)null); Resource subject; Map<String,String> graphNodeIdToTriplesMapIdMap = kr2rmlMapping.getAuxInfo().getGraphNodeIdToTriplesMapIdMap(); while (itr.hasNext()) { Statement subjMapToNodeIdStmt = itr.next(); String nodeId = subjMapToNodeIdStmt.getObject().toString(); subject = subjMapToNodeIdStmt.getSubject(); if (subject != null) { StmtIterator itr2 = model.listStatements(null, model.getProperty(Uris.RR_SUBJECTMAP_URI), subject); while (itr2.hasNext()) { String triplesMapId = itr2.next().getSubject().toString(); graphNodeIdToTriplesMapIdMap.put(nodeId, triplesMapId); } } } }
protected Model getDefaultModel() { Model model = ModelFactory.createDefaultModel(); Resource resource = model.createResource("", model.createResource("http://example.com/ns#Bug")); resource.addProperty(RDF.type, model.createResource(LDP.RDFSource.stringValue())); resource.addProperty( model.createProperty("http://example.com/ns#severity"), "High"); resource.addProperty(DCTerms.title, "Another bug to test."); resource.addProperty(DCTerms.description, "Issues that need to be fixed."); return model; }
private static Resource otherModel(Resource r, Model model) { if ( r.isURIResource() ) return model.createResource(r.getURI()) ; if ( r.isAnon() ) return model.createResource(r.getId()) ; // Literals do not need converting. return r ; }
private static boolean hasNoCompetingSubclass( List<RDFNode> types, Resource candidate ) { for (int j = 0; j < types.size(); j += 1) { Resource other = (Resource) types.get( j ); if (other.hasProperty( RDFS.subClassOf, candidate ) && !candidate.equals( other )) return false; } return true; }
public String getLabel() { Statement label = wrapped.getProperty(RDFS.label); return label == null ? wrapped.getLocalName() : label.getObject().toString(); }
/** * Returns a pair of models. The first contains any statement containing at * least one blank node. The second contains all remaining statements. * @param g * @return */ private Model[] separateStatementsWithBlankNodes(Graph g) { Model gm = ModelFactory.createModelForGraph(g); Model blankNodeModel = ModelFactory.createDefaultModel(); Model nonBlankNodeModel = ModelFactory.createDefaultModel(); StmtIterator sit = gm.listStatements(); while (sit.hasNext()) { Statement stmt = sit.nextStatement(); if (!stmt.getSubject().isAnon() && !stmt.getObject().isAnon()) { nonBlankNodeModel.add(stmt); } else { blankNodeModel.add(stmt); } } Model[] result = new Model[2]; result[0] = blankNodeModel; result[1] = nonBlankNodeModel; return result; }
Model m = ModelFactory.createDefaultModel(); for (StmtIterator i = r.listProperties(); i.hasNext(); ) { Statement s = i.nextStatement(); m.add( s ); if (s.getObject() instanceof Resource) { queue.add( s.getObject() );
public static List<RDFNode> multiValue(Resource r, Property p) { List<RDFNode> values = new ArrayList<RDFNode>() ; StmtIterator sIter = r.listProperties(p) ; while(sIter.hasNext()) { Statement s = sIter.nextStatement() ; values.add(s.getObject()) ; } return values; }
protected Content getInitialContent( Assembler a, Resource root ) { Model partial = ModelFactory.createDefaultModel(); Resource combined = partial.createResource(); for (StmtIterator it = root.listProperties( JA.initialContent ); it.hasNext();) transferContentProperties( partial, it.nextStatement().getResource(), combined ); return contentFromModel( a, root, partial, combined ); }
/** * Add a configuration description for this reasoner into a partial * configuration specification model. * @param configSpec a Model into which the configuration information should be placed * @param base the Resource to which the configuration parameters should be added. */ @Override public void addDescription(Model configSpec, Resource base) { if (configuration != null) { StmtIterator i = configuration.listProperties(); while (i.hasNext()) { Statement st = i.nextStatement(); configSpec.add(base, st.getPredicate(), st.getObject()); } } }
private static URI getSWRLVariable(String argument){ Resource variableResource = null; String variableString = argument.substring(1); variableResource = ModelFactory.createDefaultModel().createResource(kb.getPrefixURI("var")+variableString); try { return new URI(variableResource.getURI()); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
private void loadMetadataBlock(Statement md) { Resource block = md.getResource(); String taggedName = RDFUtils.getStringValue(block, API.name); List<Statement> ss = block.listProperties().toList(); Model target = ModelFactory.createDefaultModel(); if (s.getPredicate().equals(API.name)) { target.add(s); Resource outBlock = block.inModel(target); blocks.put(name, new State(enabled, outBlock));
/** * Creates quality metadata * * @return Dataset with quality metadata which needs to be attached to the assessed dataset. * @throws MetadataException if there is no observation data calculated. */ public Dataset createQualityMetadata() throws MetadataException{ Model defaultModel = ModelFactory.createDefaultModel(); Dataset dataset = null; if (this.metadata.size() == 0) throw new MetadataException("No Metric Observations Recorded"); defaultModel.add(qualityGraph, RDF.type, DAQ.QualityGraph); defaultModel.add(qualityGraph, CUBE.structure, DAQ.dsd); dataset = new DatasetImpl(defaultModel); dataset.addNamedModel(this.qualityGraph.getURI(), this.metadata); return dataset; }
public RDFNode rename( RDFNode n ) { if (n.isAnon()) return n; if (n.isLiteral()) return rename( (Literal) n ); Resource r = n.asResource(); String givenURI = r.getURI(); String uri = pe.rename( givenURI ); return uri == givenURI ? n : r.getModel().createResource( uri ); }
public Proxy getProxy() throws OREException { try { Selector selector = new SimpleSelector(null, ORE.proxyFor, res); StmtIterator itr = model.listStatements(selector); if (itr.hasNext()) { Statement statement = itr.nextStatement(); Proxy proxy = JenaOREFactory.createProxy(model, new URI(statement.getSubject().getURI())); return proxy; } return null; } catch (URISyntaxException e) { throw new OREException(e); } }
public static String getAsStringValue(Resource r, Property p) { if ( ! atmostOneProperty(r, p) ) throw new NotUniqueException(r, p) ; Statement s = r.getProperty(p) ; if ( s == null ) return null ; if ( s.getObject().isResource() ) return s.getResource().getURI() ; return s.getString() ; }
public void setTypes(List<URI> types) { super.setTypes(types); // ensure that the required type is still set Selector selector = new SimpleSelector(res, RDF.type, ORE.Proxy); StmtIterator itr = model.listStatements(selector); if (!itr.hasNext()) { res.addProperty(RDF.type, ORE.Proxy); } }
/** * <p>Add the ontologies imported by the given model to the end of the queue.</p> */ protected void queueImports( Model model, List<String> readQueue, Profile profile ) { if (model instanceof OntModel) { // add the imported ontologies to the queue readQueue.addAll( ((OntModel) model).listImportedOntologyURIs() ); } else { // we have to do the query manually StmtIterator i = model.listStatements( null, profile.IMPORTS(), (RDFNode) null ); while (i.hasNext()) { // read the next import statement and add to the queue readQueue.add( i.nextStatement().getResource().getURI() ); } } }
private void checkRelative(Model model) { assertEquals(1, model.size()); final Statement statement = model.listStatements().next(); assertEquals("http://example.com/value", statement.getPredicate().toString()); assertEquals("Test", statement.getString()); assertEquals("http://example.com/test", statement.getSubject().toString()); }