本文整理汇总了Java中org.apache.jena.query.ParameterizedSparqlString类的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedSparqlString类的具体用法?Java ParameterizedSparqlString怎么用?Java ParameterizedSparqlString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterizedSparqlString类属于org.apache.jena.query包,在下文中一共展示了ParameterizedSparqlString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLabel
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
/**
* Return the label for this object in the selected language
* @param language - the language for which the label is requested
* @return - the label in the requested language.
* @throws ModelException - thrown if there are multiple labels present for this object in this language
*/
public Label getLabel(Language language) throws ModelException {
String sparql = "SELECT ?label WHERE { ?objectURI rdfs:label ?label . FILTER(LANG(?label) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("objectURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(language.getCode(), ""));
Query query = QueryFactory.create(parameterizedSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet resultSet = qexec.execSelect();
if (!resultSet.hasNext()) return null;
QuerySolution querySolution = resultSet.next();
Label label = new Label(querySolution.getLiteral("label"));
if (!resultSet.hasNext()) return label;
throw new ModelException("%s has more than one label in language '%s'", resource.getURI(), language.getCode());
}
示例2: getParameterizedSparqlString
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
public ParameterizedSparqlString getParameterizedSparqlString(org.spinrdf.model.TemplateCall spinTemplateCall, URI base)
{
if (spinTemplateCall == null) throw new IllegalArgumentException("TemplateCall cannot be null");
if (base == null) throw new IllegalArgumentException("Base URI cannot be null");
if (spinTemplateCall.getTemplate() == null)
{
if (log.isErrorEnabled()) log.error("SPIN Template of TemplateCall '{}' not found", spinTemplateCall);
throw new OntologyException("SPIN Template of TemplateCall '" + spinTemplateCall + "' not found");
}
if (spinTemplateCall.getTemplate().getBody() == null)
{
if (log.isErrorEnabled()) log.error("Body Command of SPIN Template '{}' not found (spin:body missing)", spinTemplateCall.getTemplate());
throw new OntologyException("Body Command of SPIN Template '" + spinTemplateCall.getTemplate() + "' not found (spin:body missing)");
}
return new ParameterizedSparqlString(spinTemplateCall.getTemplate().getBody().toString(), null, base.toString());
}
示例3: getSenseLabel
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
@Override
public String getSenseLabel(QName ref) {
ParameterizedSparqlString stmt = new ParameterizedSparqlString(
"SELECT ?word WHERE {\n"
+ "?sense wordnet-ontology:synset_member ?word\n"
+ "}", model);
stmt.setIri("sense", this.asRef(ref));
final String sparql = stmt.toString();
log.trace("getSenseLabel SPARQL: {}", sparql);
Query verbTxQuery = QueryFactory.create(sparql);
QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
try {
ResultSet rs = qexec.execSelect();
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
String wordLocalName = soln.get("word").asResource().getLocalName();
return wordLocalName;
}
log.warn("No wordnet-ontology:synset_member for sense " + ref);
return shortQName(ref);
} finally {
qexec.close();
}
}
示例4: getSenseRdfsLabel
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
public String getSenseRdfsLabel(QName ref) {
ParameterizedSparqlString stmt = new ParameterizedSparqlString(
"SELECT ?label WHERE {\n"
+ "?sense rdfs:label ?label\n"
+ "}", model);
stmt.setIri("sense", this.asRef(ref));
final String sparql = stmt.toString();
log.trace("getSenseLabel SPARQL: {}", sparql);
Query verbTxQuery = QueryFactory.create(sparql);
QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
try {
ResultSet rs = qexec.execSelect();
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
String translation = soln.get("label").asLiteral().getString();
return translation;
}
log.warn("No rdfs:label for sense " + ref);
return shortQName(ref);
} finally {
qexec.close();
}
}
示例5: getNounSenses
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
/**
* Mapping from {@code ind} translations to WordNet senses for noun part-of-speech.
* The value is String to save memory, it is short QName, where nsPrefix needs
* to be explictly supported, e.g. {@code wn31} for nvarps.
*
* @param nounLiteral Verb literal, please preserve capitalization because case-normalization will be performed here.
* @return
* @todo These aren't sorted/prioritized in any way.
* @todo Need Cached by EHCache or something (never expire but with invalidation), or function-based index.
*/
public List<QName> getNounSenses(final String nounLiteral) {
List<QName> senses = new ArrayList<>();
ParameterizedSparqlString sparql = new ParameterizedSparqlString(
"SELECT ?sense\n"
+ "WHERE {\n"
+ " ?sense wordnet-ontology:translation ?nounLiteral ;"
+ " wordnet-ontology:part_of_speech wordnet-ontology:noun\n"
+ "} LIMIT 100", model);
sparql.setLiteral("nounLiteral", nounLiteral.toLowerCase(), "ind");
log.trace("getNounSenses '{}' SPARQL: {}", nounLiteral, sparql);
Query verbTxQuery = QueryFactory.create(sparql.toString());
QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
try {
ResultSet rs = qexec.execSelect();
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
QName senseRes = toQName(soln.get("sense").asResource());
senses.add(senseRes);
}
} finally {
qexec.close();
}
return senses;
}
示例6: getAdjectiveSenses
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
/**
* Mapping from {@code ind} translations to WordNet senses for adjective part-of-speech.
* The value is String to save memory, it is short QName, where nsPrefix needs
* to be explictly supported, e.g. {@code wn31} for nvarps.
*
* @param adjectiveLiteral Verb literal, please preserve capitalization because case-normalization will be performed here.
* @return
* @todo These aren't sorted/prioritized in any way.
* @todo Need Cached by EHCache or something (never expire but with invalidation), or function-based index.
*/
public List<QName> getAdjectiveSenses(final String adjectiveLiteral) {
List<QName> senses = new ArrayList<>();
ParameterizedSparqlString sparql = new ParameterizedSparqlString(
"SELECT ?sense\n"
+ "WHERE {\n"
+ " ?sense wordnet-ontology:translation ?adjectiveLiteral ;"
+ " wordnet-ontology:part_of_speech wordnet-ontology:adjective\n"
+ "} LIMIT 100", model);
sparql.setLiteral("adjectiveLiteral", adjectiveLiteral.toLowerCase(), "ind");
log.trace("getAdjectiveSenses '{}' SPARQL: {}", adjectiveLiteral, sparql);
Query verbTxQuery = QueryFactory.create(sparql.toString());
QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
try {
ResultSet rs = qexec.execSelect();
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
QName senseRes = toQName(soln.get("sense").asResource());
senses.add(senseRes);
}
} finally {
qexec.close();
}
return senses;
}
示例7: getAdjectiveSatelliteSenses
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
/**
* Mapping from {@code ind} translations to WordNet senses for {@link PartOfSpeechType#ADJECTIVE_SATELLITE} part-of-speech.
* The value is String to save memory, it is short QName, where nsPrefix needs
* to be explictly supported, e.g. {@code wn31} for nvarps.
*
* @param adjectiveSatelliteLiteral Verb literal, please preserve capitalization because case-normalization will be performed here.
* @return
* @todo These aren't sorted/prioritized in any way.
* @todo Need Cached by EHCache or something (never expire but with invalidation), or function-based index.
*/
public List<QName> getAdjectiveSatelliteSenses(final String adjectiveSatelliteLiteral) {
List<QName> senses = new ArrayList<>();
ParameterizedSparqlString sparql = new ParameterizedSparqlString(
"SELECT ?sense\n"
+ "WHERE {\n"
+ " ?sense wordnet-ontology:translation ?adjectiveSatelliteLiteral ;"
+ " wordnet-ontology:part_of_speech wordnet-ontology:adjective_satellite\n"
+ "} LIMIT 100", model);
sparql.setLiteral("adjectiveSatelliteLiteral", adjectiveSatelliteLiteral.toLowerCase(), "ind");
log.trace("getAdjectiveSatelliteSenses '{}' SPARQL: {}", adjectiveSatelliteLiteral, sparql);
Query verbTxQuery = QueryFactory.create(sparql.toString());
QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
try {
ResultSet rs = qexec.execSelect();
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
QName senseRes = toQName(soln.get("sense").asResource());
senses.add(senseRes);
}
} finally {
qexec.close();
}
return senses;
}
示例8: convertToSelect
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
protected Query convertToSelect(ParameterizedSparqlString pss, Set<String> varNames) {
Query queryCpy = pss.asQuery();
queryCpy.getQueryPattern();
StringBuilder queryStr = new StringBuilder("SELECT DISTINCT ");
for(String varName : varNames) {
queryStr.append("?").append(varName).append(" ");
}
queryStr.append(queryCpy.getQueryPattern());
ParameterizedSparqlString pssSelect = new ParameterizedSparqlString();
pssSelect.setCommandText(queryStr.toString());
pssSelect.setNsPrefixes(pss.getNsPrefixMap());
pssSelect.append(" LIMIT ");
pssSelect.append(this.limit);
return pssSelect.asQuery();
}
示例9: getConcept
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
public Concept getConcept(URI uri) {
Resource conceptResource = resourceFromURI(model, uri);
String sparql = "ASK WHERE { ?conceptURI a ?classURI . ?classURI rdfs:subClassOf* skos:Concept . }";
ParameterizedSparqlString findConceptSparql = new ParameterizedSparqlString(model);
findConceptSparql.setCommandText(sparql);
findConceptSparql.setParam("conceptURI", conceptResource);
Query query = QueryFactory.create(findConceptSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
return qexec.execAsk() ? new Concept(model, conceptResource) : null;
}
示例10: getConceptScheme
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
public ConceptScheme getConceptScheme(URI uri) {
Resource conceptSchemeResource = model.getResource(uri.toString());
String sparql = "ASK WHERE { ?conceptSchemeURI a skos:ConceptScheme . }";
ParameterizedSparqlString findConceptSchemeSparql = new ParameterizedSparqlString(model);
findConceptSchemeSparql.setCommandText(sparql);
findConceptSchemeSparql.setParam("conceptSchemeURI", conceptSchemeResource);
Query query = QueryFactory.create(findConceptSchemeSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
return qexec.execAsk() ? new ConceptScheme(model, conceptSchemeResource) : null;
}
示例11: getMetadataTypeIfExists
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
public MetadataType getMetadataTypeIfExists(URI uri) throws ModelException {
String sparql = "SELECT ?metadataTypeURI WHERE { VALUES ?metadataTypeURI { ?suppliedURI } . ?metadataTypeURI a owl:DatatypeProperty . ?metadataTypeURI rdfs:range ?range . }";
ParameterizedSparqlString findConceptSchemeSparql = new ParameterizedSparqlString(model);
findConceptSchemeSparql.setCommandText(sparql);
findConceptSchemeSparql.setParam("suppliedURI", model.getResource(uri.toString()));
Query query = QueryFactory.create(findConceptSchemeSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet resultSet = qexec.execSelect();
MetadataType metadataType = null;
while (resultSet.hasNext()) {
QuerySolution querySolution = resultSet.next();
Resource range = querySolution.getResource("?range");
if (XSD.xstring.equals(range)) {
metadataType = new StringMetadataType(model, querySolution.getResource("?metadataTypeURI"));
} else if (XSD.date.equals(range)) {
metadataType = new CalendarMetadataType(model, querySolution.getResource("?metadataTypeURI"));
} else if (XSD.xboolean.equals(range)) {
metadataType = new BooleanMetadataType(model, querySolution.getResource("?metadataTypeURI"));
} else {
throw new ModelException(String.format("Unable to determine range for metadata type with URI: '%s'", uri));
}
}
return metadataType;
}
示例12: getRelationshipType
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
public RelationshipType getRelationshipType(URI uri) throws ModelException {
String sparql =
"select ?relationshipTypeUri ?relationshipBaseType ?inverseRelationshipType where {"
+ " ?relationshipTypeUri rdfs:subPropertyOf* ?relationshipBaseType ."
+ " VALUES ?relationshipTypeUri { ?suppliedURI }"
+ " VALUES ?relationshipBaseType { skos:related skos:broader skos:narrower skosxl:altLabel }"
+ " OPTIONAL { ?relationshipTypeUri owl:inverseOf ?inverseRelationshipType }"
+"}";
ParameterizedSparqlString findRelationshipTypeSparql = new ParameterizedSparqlString(model);
findRelationshipTypeSparql.setCommandText(sparql);
findRelationshipTypeSparql.setParam("suppliedURI", model.getResource(uri.toString()));
Query query = QueryFactory.create(findRelationshipTypeSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet resultSet = qexec.execSelect();
RelationshipType relationshipType = null;
while (resultSet.hasNext()) {
QuerySolution querySolution = resultSet.next();
Resource relationshipTypeResource = querySolution.getResource("?relationshipTypeUri");
Resource inverseRelationshipTypeResource = querySolution.getResource("?inverseRelationshipType");
Resource relationshipBaseTypeResource = querySolution.getResource("?relationshipBaseType");
if ("broader".equals(relationshipBaseTypeResource.getLocalName())) {
relationshipType = new HasBroaderRelationshipType(model, relationshipTypeResource, inverseRelationshipTypeResource);
} else if ("narrower".equals(relationshipBaseTypeResource.getLocalName())) {
relationshipType = new HasNarrowerRelationshipType(model, relationshipTypeResource, inverseRelationshipTypeResource);
} else if ("related".equals(relationshipBaseTypeResource.getLocalName())) {
relationshipType = new AssocativeRelationshipType(model, relationshipTypeResource, inverseRelationshipTypeResource);
} else if ("altLabel".equals(relationshipBaseTypeResource.getLocalName())) {
relationshipType = new HasEquivalentRelationshipType(model, relationshipTypeResource);
} else {
throw new ModelException("Unrecognized base type: '%s' for relationship '%s'", relationshipBaseTypeResource.getLocalName(), uri.toString());
}
}
return relationshipType;
}
示例13: deleteLabelForLanguagePostCheck
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
private void deleteLabelForLanguagePostCheck(Label label) {
String sparql = "DELETE { ?objectURI rdfs:label ?labelValue } WHERE { ?objectURI rdfs:label ?labelValue . FILTER(LANG(?labelValue) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("objectURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(label.getLanguageCode(), ""));
UpdateAction.execute(parameterizedSparql.asUpdate(), model);
}
示例14: deleteLabelPostCheck
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
private void deleteLabelPostCheck(Label label) {
String sparql = "DELETE { ?objectURI rdfs:label ?labelValue } WHERE { ?objectURI rdfs:label ?labelValue . FILTER (?labelValue = ?suppliedLabel) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("objectURI", resource);
parameterizedSparql.setParam("suppliedLabel", model.createLiteral(label.getValue(), label.getLanguageCode()));
UpdateAction.execute(parameterizedSparql.asUpdate(), model);
}
示例15: labelExistsInLanguage
import org.apache.jena.query.ParameterizedSparqlString; //导入依赖的package包/类
private boolean labelExistsInLanguage(Label label) {
String sparql = "ASK WHERE { ?objectURI rdfs:label ?label . FILTER(LANG(?label) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("objectURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(label.getLanguageCode(), ""));
Query query = QueryFactory.create(parameterizedSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
return qexec.execAsk();
}