/** * Convert the given Jena Literal to a Sesame Literal * @param theLiteral the Jena Literal to convert * @return the Jena Literal as a Sesame Literal */ public static org.openrdf.model.Literal asSesameLiteral(Literal theLiteral) { if (theLiteral == null) { return null; } else if (theLiteral.getLanguage() != null && !theLiteral.getLanguage().equals("")) { return FACTORY.createLiteral(theLiteral.getLexicalForm(), theLiteral.getLanguage()); } else if (theLiteral.getDatatypeURI() != null) { return FACTORY.createLiteral(theLiteral.getLexicalForm(), FACTORY.createURI(theLiteral.getDatatypeURI())); } else { return FACTORY.createLiteral(theLiteral.getLexicalForm()); } }
/** * Convert a Sesame Literal to a Jena Literal * @param theLiteral the Sesame literal * @return the sesame literal converted to Jena */ public static com.hp.hpl.jena.rdf.model.Literal asJenaLiteral(org.openrdf.model.Literal theLiteral) { if (theLiteral == null) { return null; } else if (theLiteral.getLanguage() != null) { return mInternalModel.createLiteral(theLiteral.getLabel(), theLiteral.getLanguage()); } else if (theLiteral.getDatatype() != null) { return mInternalModel.createTypedLiteral(theLiteral.getLabel(), theLiteral.getDatatype().toString()); } else { return mInternalModel.createLiteral(theLiteral.getLabel()); } }
public OntoRecord getSubclass(String resourceURI, String lang){ StmtIterator iter1 = model.listStatements( new SimpleSelector(ResourceFactory.createResource(resourceURI), ResourceFactory.createProperty("http://www.w3.org/2000/01/rdf-schema#subClassOf"), (RDFNode)null)); OntoRecord record = new OntoRecord(); StmtIterator iter2; while(iter1.hasNext()) { record.setUri(iter1.next().getObject().toString()); iter2 = model.listStatements( new SimpleSelector(ResourceFactory.createResource(record.getUri()), ResourceFactory.createProperty("http://www.w3.org/2000/01/rdf-schema#label"), (RDFNode)null)); while(iter2.hasNext()){ Literal res = (Literal) iter2.next().getObject(); String tmpLang = res.getLanguage(); if( tmpLang.equals("en") ){ record.setLabel(res.getString()); return record; } } } return null; }
protected void copyAllowedProperties(Model readModel, Model model, Set<Resource> classes, Set<Property> allowedProperties) { StmtIterator stmtIterator = readModel.listStatements(); Statement s; Literal label; while (stmtIterator.hasNext()) { s = stmtIterator.next(); if (classes.contains(s.getSubject()) && allowedProperties.contains(s.getPredicate()) && (!s.getObject().isAnon())) { if (s.getPredicate().equals(RDFS.label)) { label = s.getObject().asLiteral(); if (label.getLanguage().equals("en")) { model.add(s.getSubject(), RDFS.label, model.createLiteral(label.getString().toLowerCase(), "en")); } } else { model.add(s); } } } }
private static void parseN3(GrabMappingsHandler handler, String infileurl) { Model model = ModelFactory.createDefaultModel(); model.read(infileurl, "N3"); AResourceImpl sub = new AResourceImpl(); AResourceImpl pred = new AResourceImpl(); AResourceImpl objres = new AResourceImpl(); ALiteralImpl objlit = new ALiteralImpl(); StmtIterator it = model.listStatements(); while (it.hasNext()) { Statement stmt = it.nextStatement(); RDFNode object = stmt.getObject(); sub.setResource(stmt.getSubject()); pred.setResource(stmt.getPredicate()); if (object instanceof Literal) { objlit.setLiteral((Literal) object); handler.statement(sub, pred, objlit); } else { objres.setResource((Resource) object); handler.statement(sub, pred, objres); } } }
private void writeStatement(Statement stmt, PrintStream out) { String name = getQName(stmt.getPredicate()); Map<String,String> attrs = null; String value = null; RDFNode node = stmt.getObject(); if ( node.isLiteral() ) { Literal l = node.asLiteral(); value = l.getString(); String lang = l.getLanguage(); if ( !lang.isEmpty() ) { attrs = Collections.singletonMap("xml:lang", lang); } String datatype = l.getDatatypeURI(); if ( datatype != null ) { attrs = Collections.singletonMap("rdf:datatype", datatype); } } else { attrs = Collections.singletonMap("rdf:resource", getURI(node.asResource())); } writeProperty(name, attrs, value, out); }
public static void fixLanguage(StmtIterator iter, String sLang) { if ( (sLang == null) || sLang.trim().isEmpty() ) { return; } List<Statement> list = iter.toList(); for ( Statement stmt : list ) { RDFNode n = stmt.getObject(); if ( !n.isLiteral() ) { continue; } Literal l = n.asLiteral(); String sL = l.getLanguage(); if ( (sL != null) && !sL.trim().isEmpty() ) { continue; } stmt.changeObject(l.getString(), sLang); } }
@Override public void binding(String varName, RDFNode value) { // If, for a particular solution, a variable is unbound, no binding element for that variable is included in the result element. if (value == null) return; try { // start binding element atts.clear(); atts.addAttribute(dfNamespace, dfAttrVarName, dfAttrVarName, "CDATA", varName); handler.startElement(dfNamespace, dfBinding, dfBinding, atts); // binding value if (value.isLiteral()) literal((Literal) value); else if (value.isResource()) resource((Resource) value); // end binding element handler.endElement(dfNamespace, dfBinding, dfBinding); } catch (SAXException ex) { } }
private void literal(Literal l) { atts.clear(); try { String s = l.getLexicalForm(); String lang = l.getLanguage(); String dt = l.getDatatypeURI(); // Literal with lang? if (lang != null && lang.length() != 0) { atts.addAttribute(ARQConstants.XML_NS, "lang", "xml:lang", "CDATA", lang); } // Literal with datatype? if (dt != null && dt.length() != 0) { atts.addAttribute(dfNamespace, dfAttrDatatype, dfAttrDatatype, "CDATA", dt); } handler.startElement(dfNamespace, dfLiteral, dfLiteral, atts); handler.characters(s.toCharArray(), 0, s.length()); handler.endElement(dfNamespace, dfLiteral, dfLiteral); } catch (SAXException ex) { } }
/** * Gets and returns the geolocation of a POI * @param resource * @return */ private static Literal getGeoLocation(String resource){ Literal geoLocation; String sparqlquery= "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> \n" + "select distinct ?geolocation where {" + "<"+resource+"> geo:geometry ?geolocation.}\n" + "LIMIT 1 "; Query query = QueryFactory.create(sparqlquery); QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query); ResultSet results = qexec.execSelect(); if (results.hasNext() ){ QuerySolution soln = results.nextSolution(); geoLocation = soln.getLiteral("geolocation"); qexec.close(); return geoLocation; } else { qexec.close(); return null; } }
/** * Convert a Jena graph Node to a SADL model Node * @param node * @return */ protected Node graphNodeToSadlNode(com.hp.hpl.jena.graph.Node node) { if (node instanceof Node_Variable) { return new VariableNode(((Node_Variable)node).getName().substring(1)); } else if (node instanceof Node_URI) { return new NamedNode(((Node_URI)node).getURI()); } else if (node instanceof Node_Literal){ com.ge.research.sadl.model.gp.Literal lit = new com.ge.research.sadl.model.gp.Literal(); lit.setValue(((Node_Literal)node).getLiteral().getValue()); return lit; } else { return new NamedNode(node.toString()); } }
private synchronized String getMappingPrefix(String modelName) { Resource publicUri = getMappingModel().createResource(modelName); StmtIterator sitr = getMappingModel().listStatements(null, publicUrlProp, publicUri); if (sitr.hasNext()) { Resource ontSpec = sitr.nextStatement().getSubject(); Statement stmt = ontSpec.getProperty(prefixProp); if (stmt != null) { RDFNode val = stmt.getObject(); if (val.isLiteral()) { return ((Literal) val).getLexicalForm(); } } } return null; }
@Override public ITranslator getTranslatorForReasoner(String reasonerName) throws ConfigurationException { if (getConfigModel() != null) { Resource subject = getConfigModel().getResource("http://com.ge.research.sadl.configuration#" + reasonerName); if (subject != null) { Property predicate = getConfigModel().getProperty("http://com.ge.research.sadl.configuration#translatorClassName"); if (predicate != null) { StmtIterator sitr = getConfigModel().listStatements(subject, predicate, (RDFNode)null); if (sitr.hasNext()) { RDFNode rcls = sitr.next().getObject(); if (rcls instanceof Literal) { String clsName = rcls.asLiteral().getString(); return getTranslatorInstanceByClass(clsName); } } } } } return null; }
/** * Method to return the fully qualified name of the class for the current ITranslator as specified in the configuration. * @return * @throws ConfigurationException */ public String getTranslatorClassName() throws ConfigurationException { IReasoner reasonerInst = getReasonerInstance(); Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory()); StmtIterator sitr = getConfigModel().listStatements(reasonerCategory, getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null); if (sitr.hasNext()) { RDFNode clsnmnode = sitr.nextStatement().getObject(); if (clsnmnode instanceof Literal) { return ((Literal)clsnmnode).getValue().toString(); } } ITranslator translator = getTranslator(); if (translator != null) { return translator.getClass().getCanonicalName(); } throw new ConfigurationException("Unable to get current translator for unknown reason."); }
private ITranslator getTranslatorInstance() throws ConfigurationException { String translatorClassName = null; if (getConfigModel() != null) { IReasoner reasonerInst = getReasonerInstance(); Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory()); StmtIterator sitr = getConfigModel().listStatements(reasonerCategory, getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null); if (sitr.hasNext()) { RDFNode cnobj = sitr.next().getObject(); if (cnobj instanceof Literal) { translatorClassName = ((Literal)cnobj).getLexicalForm(); } } } if (translatorClassName == null) { translatorClassName = DEFAULT_TRANSLATOR; } return getTranslatorInstanceByClass(translatorClassName); }
@Override public ITranslator getTranslatorForReasoner(String reasonerName) throws ConfigurationException { if (getConfigModel() != null) { Resource subject = getConfigModel().getResource("http://com.ge.research.sadl.configuration#" + reasonerName); if (subject != null) { Property predicate = getConfigModel().getProperty("http://com.ge.research.sadl.configuration#translatorClassName"); if (predicate != null) { StmtIterator sitr = getConfigModel().listStatements(subject, predicate, (RDFNode)null); if (sitr.hasNext()) { RDFNode rcls = sitr.next().getObject(); if (rcls instanceof Literal) { String clsName = rcls.asLiteral().getString(); return getTranslatorInstanceByClass(clsName); } } } } } if (getReasoner() != null && getReasoner().getClass().getCanonicalName().equals(reasonerName)) { String transClsName = getReasoner().getDefaultTranslatorClassName(); if (transClsName != null) { return getTranslatorInstanceByClass(transClsName); } } return null; }
/** * Method to return the fully qualified name of the class for the current ITranslator as specified in the configuration. * @return * @throws ConfigurationException */ public String getTranslatorClassName() throws ConfigurationException { try { IReasoner reasonerInst = getReasonerInstance(); if (getConfigModel() != null) { Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory()); StmtIterator sitr = getConfigModel().listStatements(reasonerCategory, getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null); if (sitr.hasNext()) { RDFNode clsnmnode = sitr.nextStatement().getObject(); if (clsnmnode instanceof Literal) { return ((Literal)clsnmnode).getValue().toString(); } } } ITranslator translator = getTranslator(); if (translator != null) { return translator.getClass().getCanonicalName(); } throw new ConfigurationException("Unable to get current translator for unknown reason."); } catch (Throwable t) { return ConfigurationManager.DEFAULT_TRANSLATOR; } }
private ITranslator getTranslatorInstance() throws ConfigurationException { if (translatorClassName == null) { if (getConfigModel() != null) { IReasoner reasonerInst = getReasonerInstance(); Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory()); StmtIterator sitr = getConfigModel().listStatements(reasonerCategory, getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null); if (sitr.hasNext()) { RDFNode cnobj = sitr.next().getObject(); if (cnobj instanceof Literal) { translatorClassName = ((Literal)cnobj).getLexicalForm(); } } if (translatorClassName == null) { translatorClassName = reasonerInst.getDefaultTranslatorClassName(); } } } if (translatorClassName == null) { translatorClassName = DEFAULT_TRANSLATOR; } return getTranslatorInstanceByClass(translatorClassName); }
public void processStatement(EquationStatement element) throws JenaProcessorException, InvalidNameException, InvalidTypeException, TranslationException { SadlResource nm = element.getName(); EList<SadlParameterDeclaration> params = element.getParameter(); SadlTypeReference rtype = element.getReturnType(); Expression bdy = element.getBody(); Equation eq = createEquation(element, nm, rtype, params, bdy); addEquation(element.eResource(), eq, nm); Individual eqinst = getTheJenaModel().createIndividual(getDeclarationExtensions().getConceptUri(nm), getTheJenaModel().getOntClass(SadlConstants.SADL_BASE_MODEL_EQUATION_URI)); DatatypeProperty dtp = getTheJenaModel().getDatatypeProperty(SadlConstants.SADL_BASE_MODEL_EQ_EXPRESSION_URI); Literal literal = getTheJenaModel().createTypedLiteral(eq.toString()); if (eqinst != null && dtp != null) { // these can be null during clean/build with resource open in editor eqinst.addProperty(dtp, literal); } }
protected Object processSubjHasPropUnitExpression(SubjHasProp expr) throws InvalidNameException, InvalidTypeException, TranslationException { Expression valexpr = expr.getLeft(); Object valarg = processExpression(valexpr); if (ignoreUnittedQuantities) { return valarg; } String unit = SadlASTUtils.getUnitAsString(expr); if (valarg instanceof com.ge.research.sadl.model.gp.Literal) { ((com.ge.research.sadl.model.gp.Literal) valarg).setUnits(unit); return valarg; } com.ge.research.sadl.model.gp.Literal unitLiteral = new com.ge.research.sadl.model.gp.Literal(); unitLiteral.setValue(unit); return createBinaryBuiltin("unittedQuantity", valarg, unitLiteral); }
public Object processExpression(UnitExpression expr) throws InvalidNameException, InvalidTypeException, TranslationException { String unit = expr.getUnit(); Expression value = expr.getLeft(); Object valobj = null; valobj = processExpression(value); if (ignoreUnittedQuantities) { return valobj; } if (valobj instanceof com.ge.research.sadl.model.gp.Literal) { ((com.ge.research.sadl.model.gp.Literal) valobj).setUnits(unit); return valobj; } com.ge.research.sadl.model.gp.Literal unitLiteral = new com.ge.research.sadl.model.gp.Literal(); unitLiteral.setValue(unit); return createBinaryBuiltin("unittedQuantity", valobj, unitLiteral); }
private TypeCheckInfo getType(SadlConstantLiteral expression) throws TranslationException, InvalidNameException, InvalidTypeException { String term = expression.getTerm(); Literal litval = null; if (term.equals(SadlConstants.CONSTANT_PI)) { litval = theJenaModel.createTypedLiteral(Math.PI); } else if (term.equals(SadlConstants.CONSTANT_E)) { litval = theJenaModel.createTypedLiteral(Math.E); } else { throw new TranslationException("Unhandled SadlConstantLiteral type: " + expression.getClass().getCanonicalName()); } NamedNode tctype = getModelProcessor().validateNamedNode(new NamedNode(XSD.decimal.getURI(), NodeType.DataTypeNode)); ConceptName numberLiteralConceptName = getModelProcessor().namedNodeToConceptName(tctype); TypeCheckInfo litTci = new TypeCheckInfo(numberLiteralConceptName, litval, ExplicitValueType.VALUE, this, expression); litTci.setTypeCheckType(tctype); return litTci; }
public boolean checkDataPropertyValueInRange(OntModel theJenaModel2, Resource subj, OntProperty prop, Literal val) { OntResource rng = prop.getRange(); if (rng == null) { return true; } String ptype = prop.getRange().getURI(); if (ptype == null) { return true; } String dtype = val.getDatatypeURI(); if (dtype.equals(ptype)) { return true; } if (dtype.equals(XSD.xint.getURI())) { // the literal is an integer if (ptype.equals(XSD.integer.getURI())) return true; if (ptype.equals(XSD.xlong.getURI())) return true; } return false; }
private void populateProblemLists() throws ProblemListInitialisationException{ temporaryURI1 = datasetSample.createResource("ex:Joe"); Literal joeLiteral = datasetSample.createLiteral("JoeDoe"); temporaryURI2 = datasetSample.createResource("ex:UniBonn"); Literal uniBonnLiteral = datasetSample.createLiteral("UniBonn"); List<Quad> lQuad = new ArrayList<Quad>(); lQuad.add(new Quad(null, temporaryURI1.asNode(), RDFS.label.asNode(), joeLiteral.asNode())); lQuad.add(new Quad(null, temporaryURI2.asNode(), RDFS.label.asNode(), uniBonnLiteral.asNode())); quadProblemList = new ProblemList<Quad>(lQuad); List<Resource> lResource = new ArrayList<Resource>(); lResource.add(temporaryURI1); lResource.add(temporaryURI2); resourceProblemList = new ProblemList<Resource>(lResource); }
public void queryResultSet() { Query q = QueryFactory.create(query); QueryExecution qe = QueryExecutionFactory.create(q, model); ResultSet rs = qe.execSelect(); while (rs.hasNext()) { QuerySolution soln = rs.nextSolution(); // RDFNode x = soln.get("?o") ; // Get a result variable by name. // Resource r = soln.getResource("?o"); // Get a result variable - // must be a resource Literal l = soln.getLiteral("?o"); // Get a result variable - must // be a literal literalsListDuplicates.add(l.getLexicalForm()); literalsListNODuplicates.add(l.getLexicalForm()); } // NodeIterator itr = model.listObjects(); // while (itr.hasNext()) { // System.out.println(itr.next()); // } }
/** * Return the URI of the type of the literal node passed as argument. * * @param n the literal node for which to return the typer * @return a URI representing the type of the literal content, or null if the literal is untyped * @throws IllegalArgumentException in case the node is no literal */ @Override public URI getLiteralType(RDFNode n) { if(n.isLiteral()) { if (((Literal)n).getLanguage() != null) { try { return new URI(((Literal)n).getDatatypeURI()); } catch (URISyntaxException e) { throw new IllegalArgumentException("the type of node "+n+" was not a valid URI"); } } else { return null; } } else { throw new IllegalArgumentException("the node "+n+" is not a literal, cannot return literal type"); } }
protected void writePredicate(Statement stmt, final PrintWriter writer) { final Property predicate = stmt.getPredicate(); final RDFNode object = stmt.getObject(); writer.print(space+space+ "<" + startElementTag( predicate.getNameSpace(), predicate.getLocalName())); if (object instanceof Resource) { writer.print(" "); writeResourceReference(((Resource) object), writer); writer.println("/>"); } else { writeLiteral((Literal) object, writer); writer.println( "</" + endElementTag( predicate.getNameSpace(), predicate.getLocalName()) + ">"); } }
protected void writeLiteral( Literal l, PrintWriter writer ) { String lang = l.getLanguage(); String form = l.getLexicalForm(); if (!lang.equals("")) { writer.print(" xml:lang=" + attributeQuoted( lang )); } if (l.isWellFormedXML() && !blockLiterals) { writer.print(" " + rdfAt("parseType") + "=" + attributeQuoted( "Literal" )+">"); writer.print( form ); } else { String dt = l.getDatatypeURI(); if (dt != null) writer.print( " " + rdfAt( "datatype" ) + "=" + substitutedAttribute( dt ) ); writer.print(">"); writer.print( Util.substituteEntitiesInElementContent( form ) ); } }
private static boolean addDetailsEntry(Context ctxt, PresentationOntology.Item property, Object obj, boolean isUnverified, ViewGroup parent, OnClickListener clickListener, boolean longVersion) { SpannableStringBuilder text = new SpannableStringBuilder(); text.append(property.label); text.append(": "); // todo this may need localization text.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); String value = null; if (obj instanceof Literal) { value = ((Literal)obj).getLexicalForm(); } else { value = obj.toString(); } value = value.trim(); if ("".equals(value)) { return false; } text.append(value); if (isUnverified) { text.append(" "); text.append(unverified); } TextView entry = newTextViewWithDetailsStyle(ctxt, property.id, property.label, property.comment, value, text, clickListener, longVersion); parent.addView(entry); return true; }
@SuppressWarnings("unchecked") public void removeClassesComments ( float percentage ) { ArrayList<Literal> comments = new ArrayList<Literal>(); List<OntClass> classes = modifiedModel.listNamedClasses().toList(); ArrayList<OntClass> classesTo = new ArrayList<OntClass>(); int nbClasses = classes.size(); int toBeRemoved = Math.round( percentage*nbClasses ); //number of classes comments to be removed int [] n = this.randNumbers(nbClasses, toBeRemoved); for ( int i=0; i<toBeRemoved; i++ ) { OntClass cls = classes.get(n[i]); classesTo.add( cls ); } for ( OntClass c : classesTo ) { for (Iterator it2 = c.listComments(null); it2.hasNext();) comments.add(((Literal) it2.next())); for (Literal lit : comments) // remove comments c.removeComment( lit ); comments.clear(); } }
@SuppressWarnings("unchecked") public void removePropertiesComments ( float percentage ) { ArrayList<Literal> comments = new ArrayList<Literal>(); // an array list to hold all the comments List<OntProperty> properties = modifiedModel.listAllOntProperties().toList(); ArrayList<OntProperty> propertiesTo = new ArrayList<OntProperty>(); int nbProperties = properties.size(); int toBeRemoved = Math.round( percentage*nbProperties ); //the number of properties comments to be removed int [] n = this.randNumbers(nbProperties, toBeRemoved); for ( int i=0; i<toBeRemoved; i++ ) { OntProperty p = properties.get(n[i]); propertiesTo.add( p ); } for ( OntProperty prop : propertiesTo ) { for (Iterator it2 = prop.listComments(null); it2.hasNext();) // get all comments comments.add(((Literal) it2.next())); for (Literal lit : comments) //remove comments prop.removeComment( lit ); comments.clear(); } }
protected void getEntityAnnotations( Object o, Set<String> annots, String lang, Set<Object> entitiesTraversed) throws OntowrapException { StmtIterator stmtIt = onto.listStatements((Resource)o,null,(RDFNode)null); while (stmtIt.hasNext()) { Statement st = stmtIt.next(); if ( st.getPredicate().canAs(AnnotationProperty.class)) { RDFNode obj= st.getObject(); if (obj.isLiteral()) { Literal l =obj.as(Literal.class); if (lang==null || lang.equals(l.getLanguage())) { annots.add(l.getLexicalForm()); } } else if (obj.isResource() && !entitiesTraversed.contains(st.getSubject())) { entitiesTraversed.add(st.getSubject()); getEntityAnnotations(obj, annots, lang, entitiesTraversed); } } } }
protected void getEntityAnnotations( Object o, Set<Annotation> annots, Set<Object> entitiesTraversed) throws OntowrapException { StmtIterator stmtIt = onto.listStatements((Resource)o,null,(RDFNode)null); while (stmtIt.hasNext()) { Statement st = stmtIt.next(); if ( st.getPredicate().canAs(AnnotationProperty.class)) { RDFNode obj= st.getObject(); if (obj.isLiteral()) { Literal l =obj.as(Literal.class); annots.add(new Annotation(l.getLexicalForm(),l.getLanguage())); } else if (obj.isResource() && !entitiesTraversed.contains(st.getSubject())) { entitiesTraversed.add(st.getSubject()); getEntityAnnotations(obj, annots,entitiesTraversed); } } } }
private ArrayList<Dataset> fetchDatasets() { String query = "select * where { ?x a <http://rdfs.org/ns/void#Dataset> . " + "?x <http://rdfs.org/ns/void#uriSpace> ?urispace . " + "?x <http://www.w3.org/2000/01/rdf-schema#label> ?label } " + "ORDER BY ?label"; Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ); QueryExecution qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery, graph); ResultSet results = qexec.execSelect(); ArrayList<Dataset> arr = new ArrayList<>(); while (results.hasNext()) { QuerySolution n = results.next(); Resource v = n.getResource("x"); Literal label = n.getLiteral("label"); try { // FIXME wrong URIs (as literals) give an exception RDFNode uri = n.get("urispace"); arr.add(new Dataset(v.getURI(), label.getString(), uri.toString())); } catch (ClassCastException e) { } } return arr; }
private ArrayList<FrameworkVersion> fetchFrameworks() { String query = "select * where { ?v a <http://www.linklion.org/ontology#LDFrameworkVersion> . ?f a <http://www.linklion.org/ontology#LDFramework> . " + "?f <http://usefulinc.com/ns/doap#release> ?v . ?f <http://xmlns.com/foaf/0.1/homepage> ?url . " + "?v <http://www.w3.org/2000/01/rdf-schema#label> ?label . ?v <http://usefulinc.com/ns/doap#revision> ?ver } " + "ORDER BY ?label"; Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ); QueryExecution qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery, graph); ResultSet results = qexec.execSelect(); ArrayList<FrameworkVersion> arr = new ArrayList<>(); while (results.hasNext()) { QuerySolution n = results.next(); Resource v = n.getResource("v"); Resource url = n.getResource("url"); Literal label = n.getLiteral("label"); Literal ver = n.getLiteral("ver"); arr.add(new FrameworkVersion(v.getURI(), label.getString(), url.getURI(), ver.getString())); } return arr; }
private ArrayList<Algorithm> fetchAlgorithms() { String query = "select * where { ?x a <http://www.linklion.org/ontology#Algorithm> . " + "?x <http://xmlns.com/foaf/0.1/homepage> ?url . " + "?x <http://www.w3.org/2000/01/rdf-schema#label> ?label } " + "ORDER BY ?label"; Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ); QueryExecution qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery, graph); ResultSet results = qexec.execSelect(); ArrayList<Algorithm> arr = new ArrayList<>(); while (results.hasNext()) { QuerySolution n = results.next(); Resource v = n.getResource("x"); Resource url = n.getResource("url"); Literal label = n.getLiteral("label"); arr.add(new Algorithm(v.getURI(), label.getString(), url.getURI())); } return arr; }