本文整理汇总了Java中org.apache.jena.rdf.model.RDFNode.isLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java RDFNode.isLiteral方法的具体用法?Java RDFNode.isLiteral怎么用?Java RDFNode.isLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.RDFNode
的用法示例。
在下文中一共展示了RDFNode.isLiteral方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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";
}
示例2: mergeDescription
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void mergeDescription(Resource ir, Resource r, boolean flagOK, Map<RDFNode,RDFNode> visited) {
for (StmtIterator si = r.listProperties(); si.hasNext(); ) {
Statement stmt = si.nextStatement();
Property p = stmt.getPredicate();
RDFNode o = stmt.getObject();
if (flagOK && r.hasProperty(RDF.type, OWL.Class))
ir.addProperty(RDF.type, infModel.getResource(Gloze.OK));
if (o.isLiteral())
ir.addProperty(p,o);
else if (!o.isAnon())
ir.addProperty(p,infModel.createResource(((Resource)o).getURI()));
else if (o.isAnon() && visited.containsKey(o))
ir.addProperty(p,visited.get(o));
else { // recursively merge anonymous objects
Resource a = infModel.createResource();
visited.put(o,a);
ir.addProperty(p,a);
mergeDescription(a, (Resource)o, false, visited);
}
}
}
示例3: mergeData
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public void mergeData(Model mainConferenceModel) {
StmtIterator stmtIterator = dataModel.listStatements();
while (stmtIterator.hasNext()) {
Statement stmt = stmtIterator.next();
RDFNode object = stmt.getObject();
if (object.isLiteral()) {
if (!mainConferenceModel.contains(stmt.getSubject(),
stmt.getPredicate(), (RDFNode) null)) {
mainConferenceModel.add(stmt);
}
} else {
if (!mainConferenceModel.contains(stmt))
mainConferenceModel.add(stmt);
}
}
}
示例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: getVRankOfResource
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
static float getVRankOfResource(String uri) {
uri = "<" + uri + ">";
String var = "v";
String queryString = Constants.PREFIX_VRANK +
"SELECT ?" + var + "\n" +
"FROM <http://dbpedia.org> \n" +
"FROM <http://people.aifb.kit.edu/ath/#DBpedia_PageRank> \n" +
"WHERE {\n" +
uri + " vrank:hasRank/vrank:rankValue ?" + var + ".\n" +
"}\n";
try {
ResultSet results = SPARQLClient.runSelectQuery(queryString, Constants.DBPEDIA_SPARQL_SERVICE);
if (results != null) {
while (results.hasNext()) {
QuerySolution result = results.next();
RDFNode vRank = result.get(var);
if (vRank != null && vRank.isLiteral()) {
Literal literal = (Literal) vRank;
return (literal.getFloat());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
示例6: getStringLiteral
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
static String getStringLiteral(RDFNode node) {
String literal = null;
if (node != null && node.isLiteral()) {
literal = ((Literal) node).getLexicalForm();
}
return literal;
}
示例7: getResultSetAsObjectList
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
static List<LinkSUMResultRow> getResultSetAsObjectList(ResultSet resultSet) {
List<LinkSUMResultRow> rows = new ArrayList<>();
String subject = "subject";
String predicate = "pred";
String object = "object";
String subLabel = "sublabel";
String predLabel = "predlabel";
String obLabel = "oblabel";
String vRank = "v";
if (resultSet != null) {
while (resultSet.hasNext()) {
QuerySolution result = resultSet.next();
LinkSUMResultRow.LinkSUMResultRowBuilder builder = LinkSUMResultRow.builder();
if (result != null) {
RDFNode subjectNode = result.get(subject);
RDFNode predicateNode = result.get(predicate);
RDFNode objectNode = result.get(object);
builder
.subject(subjectNode != null ? subjectNode.toString() : null)
.predicate(predicateNode != null ? predicateNode.toString() : null)
.object(objectNode != null ? objectNode.toString() : null)
.subjectLabel(getStringLiteral(result.get(subLabel)))
.predicateLabel(getStringLiteral(result.get(predLabel)))
.objectLabel(getStringLiteral(result.get(obLabel)));
RDFNode vRankNode = result.get(vRank);
if (vRankNode != null && vRankNode.isLiteral()) {
Literal literal = (Literal) vRankNode;
builder.vRank(literal.getFloat());
}
rows.add(builder.build());
}
}
}
return rows;
}
示例8: addResultsToList
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
static void addResultsToList(ResultSet results, List<String> resources, String var) {
if (results != null) {
while (results.hasNext()) {
QuerySolution result = results.next();
if (result != null) {
RDFNode n = result.get(var);
String nameLiteral;
if (n.isLiteral()) {
nameLiteral = ((Literal) n).getLexicalForm();
resources.add(nameLiteral);
}
}
}
}
}
示例9: getImageName
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
protected String getImageName(Model model, String subjUri) {
if (model == null) {
return null;
}
Resource subj = model.getResource(subjUri);
NodeIterator iterator = model.listObjectsOfProperty(subj, HOBBIT.imageName);
if (iterator.hasNext()) {
RDFNode node = iterator.next();
if (node.isLiteral()) {
return node.asLiteral().getString();
}
}
return null;
}
示例10: getImageName
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
protected static String getImageName(Model model, String subjUri) {
if (model == null) {
return null;
}
Resource subj = model.getResource(subjUri);
NodeIterator iterator = model.listObjectsOfProperty(subj, HOBBIT.imageName);
if (iterator.hasNext()) {
RDFNode node = iterator.next();
if (node.isLiteral()) {
return node.asLiteral().getString();
}
}
return null;
}
示例11: getNodeLabel
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public String getNodeLabel(RDFNode node) {
if(node.isLiteral()) {
return node.asNode().getLiteralLexicalForm();
}
else {
return getLabel((Resource)node);
}
}
示例12: parseGraph
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private Graph parseGraph(RDFNode node) {
Model model = JenaUtil.createDefaultModel();
if(node.isLiteral()) {
String str = node.asLiteral().getLexicalForm();
model.read(new ByteArrayInputStream(str.getBytes()), "urn:x-dummy", FileUtils.langTurtle);
}
return model.getGraph();
}
示例13: getLanguages
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
protected List<Locale> getLanguages(Property property)
{
if (property == null) throw new IllegalArgumentException("Property cannot be null");
List<Locale> languages = new ArrayList<>();
Resource langs = getPropertyResourceValue(property);
if (langs != null)
{
if (!langs.canAs(RDFList.class))
{
if (log.isErrorEnabled()) log.error("ldt:lang value is not an rdf:List on template '{}'", getURI());
throw new OntologyException("ldt:lang value is not an rdf:List on template '" + getURI() +"'");
}
// could use list order as priority (quality value q=)
RDFList list = langs.as(RDFList.class);
ExtendedIterator<RDFNode> it = list.iterator();
try
{
while (it.hasNext())
{
RDFNode langTag = it.next();
if (!langTag.isLiteral())
{
if (log.isErrorEnabled()) log.error("Non-literal language tag (ldt:lang member) on template '{}'", getURI());
throw new OntologyException("Non-literal language tag (ldt:lang member) on template '" + getURI() +"'");
}
languages.add(Locale.forLanguageTag(langTag.asLiteral().getString()));
}
}
finally
{
it.close();
}
}
return languages;
}
示例14: getAgents
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private List<Agent> getAgents(URI base, Individual in,
ObjectProperty property) {
List<Agent> creators = new ArrayList<>();
for (Individual agent : listObjectProperties(in, property)) {
Agent a = new Agent();
if (agent.getURI() != null)
a.setUri(relativizeFromBase(agent.getURI(), base));
RDFNode name = agent.getPropertyValue(foafName);
if (name != null && name.isLiteral())
a.setName(name.asLiteral().getLexicalForm());
creators.add(a);
}
return creators;
}
示例15: addProperty
import org.apache.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public void addProperty(Property property, RDFNode value) {
if (value.isLiteral() || value.isURIResource()) {
properties.add(new CommandProperty(property, value));
}
}