本文整理汇总了Java中org.apache.jena.query.ParameterizedSparqlString.setCommandText方法的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedSparqlString.setCommandText方法的具体用法?Java ParameterizedSparqlString.setCommandText怎么用?Java ParameterizedSparqlString.setCommandText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.query.ParameterizedSparqlString
的用法示例。
在下文中一共展示了ParameterizedSparqlString.setCommandText方法的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: 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();
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
示例8: 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);
}
示例9: 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();
}
示例10: labelExists
import org.apache.jena.query.ParameterizedSparqlString; //导入方法依赖的package包/类
private boolean labelExists(Label label) {
String sparql = "ASK WHERE { ?objectURI rdfs:label ?label }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("objectURI", resource);
parameterizedSparql.setParam("label", model.createLiteral(label.getValue(), label.getLanguageCode()));
Query query = QueryFactory.create(parameterizedSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
return qexec.execAsk();
}
示例11: deleteLabelForLanguagePostCheck
import org.apache.jena.query.ParameterizedSparqlString; //导入方法依赖的package包/类
private void deleteLabelForLanguagePostCheck(Label label) {
String sparql = "DELETE { ?conceptSchemeURI rdfs:label ?labelValue } WHERE { ?conceptSchemeURI rdfs:label ?labelValue . FILTER(STRLANG(?label) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("conceptSchemeURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(label.getValue(), label.getLanguageCode()));
UpdateRequest updateRequest = UpdateFactory.create(parameterizedSparql.getCommandText());
UpdateAction.execute(updateRequest, model);
}
示例12: deleteLabelPostCheck
import org.apache.jena.query.ParameterizedSparqlString; //导入方法依赖的package包/类
private void deleteLabelPostCheck(Label label) {
String sparql = "DELETE { ?conceptSchemeURI rdfs:label ?labelValue } WHERE { }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("conceptSchemeURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(label.getValue(), label.getLanguageCode()));
UpdateRequest updateRequest = UpdateFactory.create(parameterizedSparql.getCommandText());
UpdateAction.execute(updateRequest, model);
}
示例13: labelExistsInLanguage
import org.apache.jena.query.ParameterizedSparqlString; //导入方法依赖的package包/类
private boolean labelExistsInLanguage(Label label) {
String sparql = "ASK WHERE { ?conceptSchemeURI rdfs:label ?label . FILTER(LANG(?label) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("conceptSchemeURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(label.getLanguageCode(), ""));
Query query = QueryFactory.create(parameterizedSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
return qexec.execAsk();
}
示例14: labelExists
import org.apache.jena.query.ParameterizedSparqlString; //导入方法依赖的package包/类
private boolean labelExists(Label label) {
String sparql = "ASK * WHERE { ?conceptSchemeURI rdfs:label ?label }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("conceptSchemeURI", resource);
parameterizedSparql.setParam("selectedLabel", model.createLiteral(label.getValue(), label.getLanguageCode()));
Query query = QueryFactory.create(parameterizedSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
return qexec.execAsk();
}
示例15: getAltTermMap
import org.apache.jena.query.ParameterizedSparqlString; //导入方法依赖的package包/类
/**
* Takes an altLabel URI and returns a map with the Alt Label Text as the key and the Concept Resource object as the value.
* @param model - the underlying model containing the Semaphore model
* @param altTermRelationship - The altTermRelationship property. If Null, this will default to SKOSXL.altLabel.
* @param language - The label language to use. All other language labels will be discarded. A language of null or empty string is considered language neutral.
* @param throwOnDuplicate - If true and there is a duplicate label / key, we will throw an exception. Otherwise, a warning will be logged.
* @return A Map of AltLabel string literals (one for each language) as the key and the value of is the Concept Resource object.
* @throws ModelException - if throwOnDuplicate is set and a duplicate is encountered
*/
public static Map<String, Resource> getAltTermMap(Model model, Property altTermRelationship, String language, boolean throwOnDuplicate) throws ModelException {
if(altTermRelationship == null){
altTermRelationship = SKOSXL.altLabel;
}
if(language == null) language = "";
ParameterizedSparqlString findConceptLabelsSparql = new ParameterizedSparqlString();
findConceptLabelsSparql.setCommandText("SELECT ?conceptUri ?label { ?conceptUri ?altLabelURI ?labelUri . ?labelUri ?skosxlLiteralForm ?label. }");
findConceptLabelsSparql.setParam("altLabelURI", altTermRelationship);
findConceptLabelsSparql.setParam("skosxlPrefLabel", SKOSXL.prefLabel);
findConceptLabelsSparql.setParam("skosxlLiteralForm", SKOSXL.literalForm);
Query query = QueryFactory.create(findConceptLabelsSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet resultSet = qexec.execSelect();
Map<String, Resource> labels = new HashMap<String, Resource>();
while (resultSet.hasNext()) {
QuerySolution querySolution = resultSet.next();
Literal label = querySolution.getLiteral("?label");
if(labels.containsKey(label.getString())){
String errorString = String.format("The alternate label %s is already included in this map. Skipping.", label);
if(throwOnDuplicate) throw new ModelException(errorString);
logger.warn(errorString);
}
else if(label.getLanguage().compareTo(language) == 0){
Resource conceptResource = querySolution.getResource("?conceptUri");
labels.put(label.getString(), conceptResource);
}
}
return labels;
}