本文整理汇总了Java中com.hp.hpl.jena.rdf.model.RDFNode.toString方法的典型用法代码示例。如果您正苦于以下问题:Java RDFNode.toString方法的具体用法?Java RDFNode.toString怎么用?Java RDFNode.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.RDFNode
的用法示例。
在下文中一共展示了RDFNode.toString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nodeToString
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private static String nodeToString(RDFNode node) {
if (node.isURIResource()) {
return node.asResource().getURI();
} else if (node.isLiteral()) {
return node.asLiteral().getLexicalForm();
} else {
return node.toString();
}
}
示例2: getShortString
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static String getShortString(RDFNode node) {
if (node.isLiteral()) {
return node.toString();
} else {
return getShortString(node.asResource());
}
}
示例3: buildNotesTree
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void buildNotesTree(
Model model,
String parentResourceUri,
String notebookUri,
ConceptTreeNode parentNode,
AnnotationTransformer annotationTransformer) throws Exception {
String conceptUri;
ConceptResource concept;
RDFNode statement;
Seq seq = model.getSeq(parentResourceUri);
NodeIterator i = seq.iterator();
cat.debug("<-> concept tree builder - got root: " + parentResourceUri);
ConceptTreeNode child;
while (i.hasNext()) {
statement = i.nextNode();
// add children to parent node
conceptUri = statement.toString();
cat.debug(" <-> concept tree builder - child '" + conceptUri + "'");
concept = MindRaider.noteCustodian.get(notebookUri, conceptUri);
child = new ConceptTreeNode();
// TODO create resource clone to avoid changing of annotations
if (annotationTransformer != null) {
concept.setAnnotation(annotationTransformer.transform(concept.getAnnotation()));
}
child.setConcept(concept.resource);
parentNode.getChildren().add(child);
// now dive recursively for each existing node...
buildNotesTree(model, conceptUri, notebookUri, child, annotationTransformer);
}
}
示例4: getMapper
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private StatementHandler getMapper(Resource subject, RDFNode node, Model model)
throws JenaException, MalformedURLException {
String uri = node.toString();
if (RTM_BASENAME.equals(uri))
return new TopicNameMapper(getScope(subject, model));
else if (RTM_INSTANCE_OF.equals(uri)) {
Collection scope = getScope(subject, model);
if (scope.isEmpty())
return new InstanceMapper();
else
return new ScopedInstanceMapper(scope);
} else if (RTM_SUBJECT_IDENTIFIER.equals(uri))
return new SubjectIdentifierMapper();
else if (RTM_SOURCE_LOCATOR.equals(uri))
return new SourceLocatorMapper();
else if (RTM_SUBJECT_LOCATOR.equals(uri))
return new SubjectLocatorMapper();
else if (RTM_OCCURRENCE.equals(uri))
return new OccurrenceMapper(getType(subject, model), getScope(subject, model));
else if (RTM_ASSOCIATION.equals(uri)) {
LocatorIF srole = getTopicIndicator(subject, RTM_SUBJECT_ROLE, model);
if (srole == null)
throw new RDFMappingException("No rtm:subject-role for " + subject);
LocatorIF orole = getTopicIndicator(subject, RTM_OBJECT_ROLE, model);
if (orole == null)
throw new RDFMappingException("No rtm:object-role for " + subject);
return new AssociationMapper(srole, orole, getType(subject, model),
getScope(subject, model));
} else
throw new RDFMappingException("Unknown value for rtm:maps-to: " + uri);
}
示例5: newValue
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void newValue(RDFNode node)
{
ValueStat stat = _values.get(node);
if ( stat == null ) {
stat = new ValueStat(node.toString());
_values.put(node, stat);
}
stat.newItem();
}
示例6: getMappingResourceFromSourceName
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private Resource getMappingResourceFromSourceName() throws KarmaException {
Property sourceNameProp = model.getProperty(Uris.KM_SOURCE_NAME_URI);
RDFNode node = model.createLiteral(id.getName());
ResIterator res = model.listResourcesWithProperty(sourceNameProp, node);
List<Resource> resList = res.toList();
if (resList.size() > 1) {
throw new KarmaException("More than one resource exists with source name: " + id.getName());
} else if (resList.size() == 1) {
return resList.get(0);
} else {
//If we didnt find the sourceName in the model, maybe it is a different source with the
//same schema.
//Maybe we need to substitute the sourceName in the model with this one
NodeIterator sourceObjectIter = model.listObjectsOfProperty(sourceNameProp);
List<RDFNode> sourceObjects = sourceObjectIter.toList();
if(sourceObjects.size() > 1) {
throw new KarmaException("More than one resource exists with source name: " + id.getName());
} else if(sourceObjects.size() == 1) {
RDFNode prevSourceObject = sourceObjects.get(0);
//We got the previous source object, now get the Subject Node for this
ResIterator prevSourceSubjectsIter = model.listResourcesWithProperty(sourceNameProp, prevSourceObject);
List<Resource> prevSourceSubjects = prevSourceSubjectsIter.toList();
if (prevSourceSubjects.size() == 1) {
Resource subject = prevSourceSubjects.get(0);
model.remove(subject, sourceNameProp, prevSourceObject);
model.add(subject, sourceNameProp, node);
return subject;
} else if(prevSourceSubjects.size() > 1) {
throw new KarmaException("More than one resource exists with model source name: " + prevSourceObject.toString());
}
}
return null;
}
}
示例7: listCompetencies
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
/** Returns the representation of competences in the given model.
*
* @param SPARQLTemplate the query to select competences with a placeholder for a username
* @param model the dataset model containing the competence triples
* @return Either a LaTeX table source or a LimeSurvey template
*/
private final static String listCompetencies(final String SPARQLTemplate,final Model model) {
List<Competency> competenceList = new ArrayList<Competency>();
//int counter = 0;
StringBuffer sb = new StringBuffer();
String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX um: <http://intelleo.eu/ontologies/user-model/ns/> PREFIX c: <http://www.intelleo.eu/ontologies/competences/ns/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX pubo: <http://lod.semanticsoftware.info/pubo/pubo#> SELECT DISTINCT ?uri WHERE {?document pubo:hasAnnotation ?author. ?author rdf:type um:User. ?author rdfs:isDefinedBy ?uri.}";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
for (; results.hasNext();) {
QuerySolution soln = results.nextSolution();
RDFNode user = soln.get("?uri");
userName = user.toString();
System.out.println("\nGenerating a semantic profile for " + userName);
System.out.println("=============================================================================================");
RDFNode ne = null;
// REPLACE THE PLACEHOLDER WITH USERNAME
String SPARQL = SPARQLTemplate.replaceAll("DUMBO", userName);
Query neQuery = QueryFactory.create(SPARQL);
QueryExecution neQexec = QueryExecutionFactory.create(neQuery,model);
ResultSet neResults = neQexec.execSelect();
int rankCounter = 1;
for (; neResults.hasNext();) {
QuerySolution neSoln = neResults.nextSolution();
ne = neSoln.get("?uri");
if (ne != null) {
Competency cmpt = getInfo(ne.toString(), rankCounter++);
competenceList.add(cmpt);
} else {
System.out.println("No competencies found!");
}
}
if(mode.equalsIgnoreCase("survey")){
System.out.println("Generating LimeSurvey templates....");
generateRandomizedSurvey(competenceList);
}else{
System.out.println("Generating LaTeX templates....");
//generateLaTeXProfile(competenceList);
}
}
} finally {
qexec.close();
}
System.out.println("All done.");
return sb.toString();
}
示例8: queryWithSingleVariable
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Test
public void queryWithSingleVariable() {
// populate SPARQL SELECT Query string
StringBuilder sb = new StringBuilder();
sb.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>").append(NEWLINE);
sb.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>").append(NEWLINE);
sb.append("PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>").append(NEWLINE);
sb.append("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>").append(NEWLINE);
sb.append("PREFIX foaf: <http://xmlns.com/foaf/0.1/>").append(NEWLINE);
sb.append("PREFIX myfoaf: <http://blog.sina.com.cn/zhoujiagenontology/helloworld.owl#>").append(NEWLINE);
sb.append("PREFIX people: <http://www.people.com#>").append(NEWLINE);
sb.append("SELECT DISTINCT ?name").append(NEWLINE);
sb.append("WHERE { myfoaf:me foaf:name ?name}").append(NEWLINE);
// generate Query
Query query = QueryFactory.create(sb.toString());
// the binding variable
String field = "?name";
// the query result
String result = null;
// execute Query
QueryExecution qexec = QueryExecutionFactory.create(query, model);
System.out.println("Plan to run SPARQL query: ");
System.out.println(BOUNDARY);
System.out.println(query);
System.out.println(BOUNDARY);
ResultSet rs = qexec.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
RDFNode name = qs.get(field);
if (name != null) {
System.out.println(name);
result = name.toString();
} else {
System.out.println("No result!");
}
}
qexec.close();
// assertion
assertEquals("Semantic Web^^http://www.w3.org/2001/XMLSchema#string", result);
}
示例9: getServiceUriByServiceAddress
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private String getServiceUriByServiceAddress(String address) {
Model model = Repository.Instance().getModel();
// Create a new query
String queryString =
"PREFIX " + Prefixes.KARMA + ": <" + Namespaces.KARMA + "> \n" +
"PREFIX " + Prefixes.HRESTS + ": <" + Namespaces.HRESTS + "> \n" +
"SELECT ?s \n" +
"WHERE { \n" +
" ?s a " + Prefixes.KARMA + ":Service . \n" +
" ?s " + Prefixes.HRESTS + ":hasAddress \"" + address + "\"^^hrests:URITemplate . \n" +
" } \n";
logger.debug(queryString);
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect() ;
if (!results.hasNext())
logger.info("query does not return any answer.");
// ResultSetFormatter.out(System.out, results, query) ;
String serviceURI = "";
for ( ; results.hasNext() ; )
{
QuerySolution soln = results.nextSolution() ;
RDFNode x = soln.get("s") ; // Get a result variable by name.
serviceURI = x.toString();
logger.info("Service with id " + x.toString() + " has been found with the address " + address);
break;
}
return serviceURI;
} catch (Exception e) {
logger.info("Exception in finding a service with the address " + address + " in service repository.");
return null;
} finally {
qexec.close() ;
}
}
示例10: findModelDataInJenaData
import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public List<Map<String, String>> findModelDataInJenaData(
com.hp.hpl.jena.rdf.model.Model jenaModel, Integer limit) {
List<Map<String, String>> attValueList =
new ArrayList<Map<String,String>>();
List<String> argList = new ArrayList<String>();
String queryString = "";
queryString = this.getSparqlDataQuery(argList);
// System.out.println(queryString);
if (limit != null) {
queryString += "LIMIT " + String.valueOf(limit.intValue() + "\n");
}
// logger.debug("query= \n" + queryString);
Query query = QueryFactory.create(queryString);
// // Execute the query and obtain results
QueryExecution qexec = QueryExecutionFactory.create(query, jenaModel);
try {
ResultSet results = qexec.execSelect() ;
if (!results.hasNext()) {
logger.info("query does not return any answer.");
return null;
}
// ResultSetFormatter.out(System.out, results, query) ;
for ( ; results.hasNext() ; )
{
QuerySolution soln = results.nextSolution() ;
Map<String, String> attValues =
new HashMap<String, String>();
for (String arg : argList) {
RDFNode argNode = soln.get(arg) ;
if (argNode != null) {
String value = argNode.toString();
attValues.put(arg, value);
}
}
attValueList.add(attValues);
}
return attValueList;
} catch (Exception e) {
logger.info(e.getMessage());
return null;
} finally {
qexec.close() ;
}
}