private String asBody( RDFNode n ) { if (n.isLiteral()) return n.asLiteral().getLexicalForm(); if (n.isResource()) return n.asResource().getURI(); return n.toString(); }
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; } }
protected static void addSubclassesFrom( Model result, Model schema ) { for (StmtIterator it = schema.listStatements( ANY, RDFS.subClassOf, ANY ); it.hasNext();) { Statement s = it.nextStatement(); if (s.getSubject().isURIResource() && s.getObject().isURIResource()) result.add( s ); } }
public boolean selects(Statement s) { if (s.getObject().isResource()) { Resource res = s.getObject().asResource(); return res.equals(FOAF.Organization); } else { return false; } } };
private Map<URI, MatchResult> search(String textquery, Query sparqlQuery) { logger.debug("Executing SPARQL query: {}", sparqlQuery); QueryExecution qexec = QueryExecutionFactory.sparqlService(queryEndpoint.toString(), sparqlQuery); ResultSet resultSet = qexec.execSelect(); Map<URI, MatchResult> r = Maps.newLinkedHashMap(); while (resultSet.hasNext()) { QuerySolution solution = resultSet.next(); RDFNode s = solution.get("s"); if (s.isURIResource()) { try { String resource = s.asResource().getURI(); FreeTextMatchResult result = new FreeTextMatchResult(new URI(searchProperty + "?q=" + textquery), new URI(resource)); r.put(new URI(resource), result); } catch (URISyntaxException e) { e.printStackTrace(); } } } return r; }
protected static void addRangeTypes( Model result, Model schema ) { Model toAdd = ModelFactory.createDefaultModel(); for (StmtIterator it = schema.listStatements( ANY, RDFS.range, ANY ); it.hasNext();) { Statement s = it.nextStatement(); RDFNode type = s.getObject(); Property property = s.getSubject().as( Property.class ); for (StmtIterator x = result.listStatements( ANY, property, ANY ); x.hasNext();) { RDFNode ob = x.nextStatement().getObject(); if (ob.isResource()) toAdd.add( (Resource) ob, RDF.type, type ); } } result.add( toAdd ); }
/** Convert a model to a set of nodes with edges to other nodes */ void convert(Model m) { for (StmtIterator it = m.listStatements(); it.hasNext();) { Statement s = it.next(); RDFNode o = s.getObject(); if (o.isResource()) convert(s.getSubject(), o.asResource()); } }
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); } } } }
private void restitchItemLists(Model given, Model recon) { Statement G = given.listStatements(ANY, API.items, ANY).toList().get(0); Resource page = G.getSubject(); // Statement S = recon.listStatements(ANY, API.items, ANY).toList().get(0); Resource items = S.getObject().asResource(); S.remove(); recon.add(page, API.items, items); recon.removeAll(ANY, others, ANY); }
/** * Helper method - extracts the truth of a boolean configuration * predicate. * @param predicate the predicate to be tested * @param configuration the configuration node * @return null if there is no setting otherwise a Boolean giving the setting value */ public static Boolean checkBinaryPredicate(Property predicate, Resource configuration) { StmtIterator i = configuration.listProperties(predicate); if (i.hasNext()) { return new Boolean(i.nextStatement().getObject().toString().equalsIgnoreCase("true")); } else { return null; } }
private static void exec(String qs, Model model, Map<Node, List<Node>> multimap) { String preamble = StrUtils.strjoinNL("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>", "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>", "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>", "PREFIX owl: <http://www.w3.org/2002/07/owl#>", "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>") ; Query query = QueryFactory.create(preamble+"\n"+qs, Syntax.syntaxARQ) ; QueryExecution qexec = QueryExecutionFactory.create(query, model) ; ResultSet rs = qexec.execSelect() ; for ( ; rs.hasNext() ; ) { QuerySolution soln= rs.next() ; Node x = soln.get("x").asNode() ; Node y = soln.get("y").asNode() ; if ( ! multimap.containsKey(x) ) multimap.put(x, new ArrayList<Node>()) ; multimap.get(x).add(y) ; } } }
private void countObjectReferencesIn(Model m) { for (StmtIterator statements = m.listStatements(); statements.hasNext();) { Statement statement = statements.nextStatement(); RDFNode O = statement.getObject(); if (O.isURIResource()) { JSONLDComposer.Int count = refCount.get(O); if (count == null) refCount.put(O.asResource(), count = new Int()); count.inc(); } } }
@Override public Set<Predicate> getPredicates() { Set<Predicate> predicates = new TreeSet<Predicate>(); dataset.begin(ReadWrite.READ); QueryExecution qExec = null; try { qExec = QueryExecutionFactory.create(SELECT_PREDICATES_QUERY, dataset); ResultSet rs = qExec.execSelect(); while (rs.hasNext()) { predicates.add(new Predicate(rs.next().get("?p").toString(), 2)); } } finally { if (qExec != null) { qExec.close(); } dataset.end(); } return predicates; }
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 static String getClassLabel(Resource uri){ StmtIterator iter = InternalModelConf.getDAQModel().listStatements(uri, RDFS.label, (RDFNode) null); String label = ""; while (iter.hasNext()){ label = iter.nextStatement().getObject().toString(); } return label; }
private void parseStudyInfo(Map<String, String> properties, Statement observedInStudy) throws StudyImporterException { StmtIterator studyProperties = observedInStudy.getObject().asResource().listProperties(); while (studyProperties.hasNext()) { Statement studyProperty = studyProperties.next(); String localName = studyProperty.getPredicate().getLocalName(); if ("locality".equals(localName)) { parseLocalityInfo(properties, getTrimmedObject(studyProperty)); } else if (OF_HABITAT.equals(localName)) { properties.put(localName, getTrimmedObject(studyProperty)); } else if ("titleAndAuthors".equals(localName)) { parseTitlesAndAuthors(getTrimmedObject(studyProperty), properties); } } }
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() ; }
private Object getValue(RDFNode n, Object outer) throws Exception { if (n.isLiteral()) return n.asLiteral().getValue(); if (n.isResource()) { Statement st = n.asResource().getProperty(pValue); if (st != null) { n = st.getObject(); if (n.isLiteral()) return n.asLiteral().getValue(); return parseAnything(object(), st.getObject(), outer, null); } } throw new ParseException(this, "Unknown value type for node ''{0}''", n); }
private DataEntry getDataEntryFromRS(ResultSet rs) { DataEntry dataEntry = new DataEntry(); QuerySolution soln = rs.nextSolution(); String colName, value; boolean useColumnNumbers = this.isUsingColumnNumbers(); /* for each column get the colName and colValue and add to the data entry */ for (int i = 0; i < rs.getResultVars().size(); i++) { colName = rs.getResultVars().get(i); RDFNode node = soln.get(colName) ; if (node.isLiteral()) { value = convertRSToString(soln, colName); } else { value = soln.getResource(colName).getURI(); } dataEntry.addValue(useColumnNumbers ? Integer.toString(i + 1) : colName, new ParamValue(value)); } return dataEntry; }