本文整理匯總了Java中org.apache.jena.rdf.model.RDFNode.asResource方法的典型用法代碼示例。如果您正苦於以下問題:Java RDFNode.asResource方法的具體用法?Java RDFNode.asResource怎麽用?Java RDFNode.asResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.jena.rdf.model.RDFNode
的用法示例。
在下文中一共展示了RDFNode.asResource方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createParamValueBeans
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
private static void createParamValueBeans(Model model, Resource taskResource, NodeIterator parameterIterator,
Map<String, ConfigurationParamValueBean> parameters) {
RDFNode node;
Resource parameter;
Property paraProp;
String parameterUri;
while (parameterIterator.hasNext()) {
node = parameterIterator.next();
if (node.isResource()) {
parameter = node.asResource();
parameterUri = parameter.getURI();
paraProp = model.getProperty(parameterUri);
if (model.contains(taskResource, paraProp) && !parameters.containsKey(parameterUri)) {
ConfigurationParamValueBean paramBean = new ConfigurationParamValueBean();
paramBean.setId(parameterUri);
paramBean.setValue(RdfHelper.getStringValue(model, taskResource, paraProp));
parameters.put(parameterUri, paramBean);
}
}
}
}
示例2: getDisplayName
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
public static String getDisplayName(RDFNode node) {
if (node == null)
return "unknown";
else if (node.isAnon())
return "anon";
else if (node.isLiteral())
return node.asLiteral().getLexicalForm();
else if (node.isResource()) {
Resource resource = node.asResource();
if (resource instanceof OntResource) {
String label = ((OntResource) resource).getLabel(null);
if (label != null)
return label;
}
String localName = resource.getLocalName();
if ((localName != null) && !localName.isEmpty())
return localName;
return resource.toString();
} else
return "unknown";
}
示例3: readExecutionParameters
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
protected void readExecutionParameters(RDFNode exeParamsSubject) {
if(exeParamsSubject != null){
Resource exeParamResource = exeParamsSubject.asResource();
RDFNode exePlanner = getObject(exeParamResource, LIMES.executionPlanner, false);
if (exePlanner != null) {
configuration.setExecutionPlanner(exePlanner.toString());
} else {
logger.info("Use default execution planner.");
}
RDFNode exeRewriter = getObject(exeParamResource, LIMES.executionRewriter, false);
if (exeRewriter != null) {
configuration.setExecutionPlanner(exeRewriter.toString());
} else {
logger.info("Use default execution rewriter.");
}
RDFNode exeEngine = getObject(exeParamResource, LIMES.executionEngine, false);
if (exeEngine != null) {
configuration.setExecutionPlanner(exeEngine.toString());
} else {
logger.info("Use default execution engine.");
}
}else {
logger.info("Use default execution parameters.");
}
}
示例4: getNodeValue
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
private static String getNodeValue(RDFNode node) {
if (node.isLiteral()) {
Literal lit = node.asLiteral();
return lit.getLexicalForm();
}
if (node.isResource()) {
Resource res = node.asResource();
return res.getURI();
}
throw new RuntimeException("RDF node " + node + " is neither a literal nor a resource!");
}
示例5: listStatements
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
public static void listStatements(Collection<Statement> result, Model model, RDFNode sourceVertex, RDFNode predicate, RDFNode targetVertex) {
if(sourceVertex != null && !sourceVertex.isURIResource()) {
result = Collections.emptySet();
} else if(predicate != null && predicate.canAs(Property.class)) {
result = Collections.emptySet();
} else {
Resource s = sourceVertex == null ? null : sourceVertex.asResource();
Property p = predicate == null ? null : predicate.as(Property.class);
result = model.listStatements(s, p, targetVertex).toSet();
}
}
示例6: createEdgePalette
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
protected ColourPalette createEdgePalette(Model model) {
RDFNode node;
Resource resource1, resource2;
StmtIterator sIterator = model.listStatements(null, RDFS.subPropertyOf, (RDFNode) null);
Statement statement;
HierarchyNode hNode1, hNode2;
// Iterate over the class hierarchy triples
while (sIterator.hasNext()) {
statement = sIterator.next();
resource1 = statement.getSubject();
node = statement.getObject();
if (node.isResource()) {
resource2 = node.asResource();
if (properties.containsKey(resource1)) {
hNode1 = properties.get(resource1);
} else {
// this property is not known, add it
hNode1 = new HierarchyNode();
properties.put(resource1, hNode1);
}
if (properties.containsKey(resource2)) {
hNode2 = properties.get(resource2);
} else {
// this property is not known, add it
hNode2 = new HierarchyNode();
properties.put(resource2, hNode2);
}
// add the hierarchy information
// if there is no list of child nodes
if (hNode1.childNodes == null) {
hNode1.childNodes = new Resource[] { resource2 };
} else {
hNode1.childNodes = Arrays.copyOf(hNode1.childNodes, hNode1.childNodes.length + 1);
hNode1.childNodes[hNode1.childNodes.length - 1] = resource2;
}
// if there is no list of parent nodes
if (hNode2.parentNodes == null) {
hNode2.parentNodes = new Resource[] { resource1 };
} else {
hNode2.parentNodes = Arrays.copyOf(hNode2.parentNodes, hNode2.parentNodes.length + 1);
hNode2.parentNodes[hNode2.parentNodes.length - 1] = resource1;
}
}
}
// All properties have been collected
// The colours can be defined
for (int i = 0; i < properties.allocated.length; ++i) {
if (properties.allocated[i]) {
edgePalette.addColour(((Resource) ((Object[]) properties.keys)[i]).getURI());
}
}
// The hierarchy can be used to create colour mixtures that contain the
// hierarchy
// Search for all root nodes that have child nodes
for (int i = 0; i < properties.allocated.length; ++i) {
if (properties.allocated[i]) {
hNode1 = (HierarchyNode) ((Object[]) properties.values)[i];
if ((hNode1.childNodes != null) && (hNode1.parentNodes == null)) {
mixColours((Resource) ((Object[]) properties.keys)[i], hNode1, properties, edgePalette);
}
}
}
return edgePalette;
}
示例7: parseBenchmarkParameter
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
/**
* Parses the given parameter from the given RDFmodel and adds it to the
* given {@link BenchmarkBean}.
*
* @param model
* the RDF model containing the parameter
* @param parameter
* the {@link Resource} representing the parameter
* @param benchmarkBean
* the {@link BenchmarkBean} to which the parameter should be
* added
*/
public static void parseBenchmarkParameter(Model model, Resource parameter, BenchmarkBean benchmarkBean) {
// If this parameter can be configured
if (model.contains(parameter, RDF.type, HOBBIT.ConfigurableParameter)) {
ConfigurationParamBean configParam = new ConfigurationParamBean();
configParam.setId(parameter.getURI());
configParam.setName(RdfHelper.getLabel(model, parameter));
if (configParam.getName() == null) {
configParam.setName(parameter.getURI());
LOGGER.warn("The benchmark parameter {} does not have a label.", parameter.getURI());
}
configParam.setDescription(RdfHelper.getDescription(model, parameter));
if (configParam.getDescription() == null) {
LOGGER.warn("The benchmark parameter {} does not have a description.", parameter.getURI());
}
configParam.setDefaultValue(RdfHelper.getStringValue(model, parameter, HOBBIT.defaultValue));
configParam.setFeature(model.contains(parameter, RDF.type, HOBBIT.FeatureParameter));
NodeIterator nodeIterator = model.listObjectsOfProperty(parameter, RDFS.range);
RDFNode node;
if (nodeIterator.hasNext()) {
node = nodeIterator.next();
if (node.isResource()) {
Resource typeResource = node.asResource();
configParam.setRange(typeResource.getURI());
// If this is an XSD resource
if (XSD.getURI().equals(typeResource.getNameSpace())) {
configParam.setDatatype(parseXsdType(typeResource));
} else if (model.contains(typeResource, RDF.type, RDFS.Class)
|| model.contains(typeResource, RDF.type, OWL.Class)) {
// Maybe this parameter has a set of predefined enum
// values
configParam.setOptions(listOptions(model, typeResource));
}
}
}
// If the datatype couldn't be found and there is no list of options
if ((configParam.getDatatype() == null) && (configParam.getOptions() == null)) {
configParam.setDatatype(Datatype.STRING);
LOGGER.warn("Couldn't find datatype of parameter {}. Using String as default.", parameter.getURI());
}
benchmarkBean.getConfigurationParamNames().add(configParam.getName());
benchmarkBean.getConfigurationParams().add(configParam);
}
}
示例8: createKPIBeans
import org.apache.jena.rdf.model.RDFNode; //導入方法依賴的package包/類
private static void createKPIBeans(Model model, Resource resource, ResIterator parameterIterator,
Map<String, KeyPerformanceIndicatorBean> kpis) {
Resource kpi;
Property kpiProp;
String parameterUri;
while (parameterIterator.hasNext()) {
kpi = parameterIterator.next();
parameterUri = kpi.getURI();
kpiProp = model.getProperty(parameterUri);
// If the KPI has not been seen before AND (it is either used as
// property with the given resource OR the given resource is
// connected via hobbit:measuresKPI with the KPI)
if ((model.contains(resource, kpiProp) || model.contains(resource, HOBBIT.measuresKPI, kpi))
&& !kpis.containsKey(parameterUri)) {
KeyPerformanceIndicatorBean kpiBean = new KeyPerformanceIndicatorBean();
kpiBean.setId(parameterUri);
kpiBean.setValue(RdfHelper.getStringValue(model, resource, kpiProp));
kpiBean.setName(RdfHelper.getLabel(model, kpiProp));
if (kpiBean.getName() == null) {
kpiBean.setName(kpi.getURI());
LOGGER.info("The benchmark parameter {} does not have a label.", kpi.getURI());
}
kpiBean.setDescription(RdfHelper.getDescription(model, kpiProp));
if (kpiBean.getDescription() == null) {
LOGGER.info("The benchmark parameter {} does not have a description.", kpi.getURI());
}
NodeIterator nodeIterator = model.listObjectsOfProperty(kpi, RDFS.range);
RDFNode node;
if (nodeIterator.hasNext()) {
node = nodeIterator.next();
if (node.isResource()) {
Resource typeResource = node.asResource();
kpiBean.setRange(typeResource.getURI());
// If this is an XSD resource
if (XSD.getURI().equals(typeResource.getNameSpace())) {
kpiBean.setDatatype(parseXsdType(typeResource));
}
}
}
Resource ranking = RdfHelper.getObjectResource(model, kpi, HOBBIT.ranking);
if (ranking != null) {
kpiBean.setRanking(ranking.toString());
}
kpis.put(parameterUri, kpiBean);
}
}
}