当前位置: 首页>>代码示例>>Java>>正文


Java RDFNode.isLiteral方法代码示例

本文整理汇总了Java中com.hp.hpl.jena.rdf.model.RDFNode.isLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java RDFNode.isLiteral方法的具体用法?Java RDFNode.isLiteral怎么用?Java RDFNode.isLiteral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.hp.hpl.jena.rdf.model.RDFNode的用法示例。


在下文中一共展示了RDFNode.isLiteral方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeQueryForLong

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static long executeQueryForLong(String queryString, String serviceEndpoint, String var) {

        logger.debug("Executing query: {}", queryString);

        //Execute the query
        Map<String, RDFNode> nodeMap = executeQueryForMap(queryString, serviceEndpoint, Sets.newHashSet(var));

        RDFNode rdfNode = nodeMap.get(var);
        if (rdfNode == null) {
            throw new IllegalStateException(String.format("The result does not have a binding for the variable '%s' ", var));
        }

        if (rdfNode.isLiteral()) {
            return rdfNode.asLiteral().getLong();
        } else {
            throw new IllegalStateException(String.format("The binding for the variable '%s' is not a literal", var));
        }

    }
 
开发者ID:nandana,项目名称:ld-sniffer,代码行数:20,代码来源:SparqlUtils.java

示例2: toTurtle

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private String toTurtle(RDFNode r) {
	if (r.isURIResource()) {
		return PrettyPrinter.qNameOrURI(relativize(r.asResource().getURI()), prefixes);
	} else if (r.isLiteral()) {
		StringBuffer result = new StringBuffer(quote(r.asLiteral().getLexicalForm()));
		if (!"".equals(r.asLiteral().getLanguage())) {
			result.append("@");
			result.append(r.asLiteral().getLanguage());
		} else if (r.asLiteral().getDatatype() != null) {
			result.append("^^");
			result.append(toTurtle(ResourceFactory.createResource(r.asLiteral().getDatatypeURI())));
		}
		return result.toString();
	} else {
		if (!blankNodeMap.containsKey(r)) {
			blankNodeMap.put(r.asResource(), "_:b" + blankNodeCounter++);
		}
		return blankNodeMap.get(r);
	}
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:21,代码来源:PrettyTurtleWriter.java

示例3: compare

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public int compare(RDFNode n1, RDFNode n2) {
	if (n1.isURIResource()) {
		if (!n2.isURIResource()) return -1;
		return n1.asResource().getURI().compareTo(n2.asResource().getURI());
	}
	if (n1.isAnon()) {
		if (n2.isURIResource()) return 1;
		if (n2.isLiteral()) return -1;
		return n1.asResource().getId().getLabelString().compareTo(n2.asResource().getId().getLabelString());
	}
	if (!n2.isLiteral()) return 1;
	int cmpLex = n1.asLiteral().getLexicalForm().compareTo(n2.asLiteral().getLexicalForm());
	if (cmpLex != 0) return cmpLex;
	if (n1.asLiteral().getDatatypeURI() == null) {
		if (n2.asLiteral().getDatatypeURI() != null) return -1;
		return n1.asLiteral().getLanguage().compareTo(n2.asLiteral().getLanguage());
	}
	if (n2.asLiteral().getDatatypeURI() == null) return 1;
	return n1.asLiteral().getDatatypeURI().compareTo(n2.asLiteral().getDatatypeURI()); 
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:21,代码来源:RDFComparator.java

示例4: writeStatement

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void writeStatement(Statement stmt, PrintStream out)
{
    String             name  = getQName(stmt.getPredicate());
    Map<String,String> attrs = null;
    String             value = null;
    RDFNode node = stmt.getObject();
    if ( node.isLiteral() )
    {
        Literal l = node.asLiteral();
        value = l.getString();

        String lang = l.getLanguage();
        if ( !lang.isEmpty()  ) { attrs = Collections.singletonMap("xml:lang", lang); }

        String datatype = l.getDatatypeURI();
        if ( datatype != null ) { attrs = Collections.singletonMap("rdf:datatype", datatype); }
    }
    else {
        attrs = Collections.singletonMap("rdf:resource", getURI(node.asResource()));
    }
    writeProperty(name, attrs, value, out);
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:23,代码来源:EDMXMLWriter.java

示例5: fixLanguage

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static void fixLanguage(StmtIterator iter, String sLang)
{
	if ( (sLang == null) || sLang.trim().isEmpty() ) { return; }

	List<Statement> list = iter.toList();
	for ( Statement stmt : list )
	{
		RDFNode n = stmt.getObject();
		if ( !n.isLiteral() ) { continue; }

		Literal l = n.asLiteral();
		String sL = l.getLanguage();
		if ( (sL != null) && !sL.trim().isEmpty() ) { continue; }

		stmt.changeObject(l.getString(), sLang);
	}
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:18,代码来源:VocsUtils.java

示例6: binding

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Override
public void binding(String varName, RDFNode value) {
    // If, for a particular solution, a variable is unbound, no binding element for that variable is included in the result element.
    if (value == null)
        return;

    try {
        // start binding element
        atts.clear();
        atts.addAttribute(dfNamespace, dfAttrVarName, dfAttrVarName, "CDATA", varName);
        handler.startElement(dfNamespace, dfBinding, dfBinding, atts);

        // binding value
        if (value.isLiteral())
            literal((Literal) value);
        else if (value.isResource())
            resource((Resource) value);

        // end binding element
        handler.endElement(dfNamespace, dfBinding, dfBinding);
    } catch (SAXException ex) {
    }
}
 
开发者ID:ljo,项目名称:exist-sparql,代码行数:24,代码来源:JenaResultSet2Sax.java

示例7: getSourceType

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private SourceTypes getSourceType(Resource mappingResource)
{
	Property sourceNameProp = model.getProperty(Uris.KM_SOURCE_TYPE_URI);
	Statement s = model.getProperty(mappingResource, sourceNameProp);
	String sourceType = null;
	if(s != null)
	{
		RDFNode node = s.getObject();
		if(node != null && node.isLiteral())
		{
			sourceType = node.asLiteral().getString();
			return SourceTypes.valueOf(sourceType);
		}
	}
	return SourceTypes.CSV;
	
	
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:19,代码来源:WorksheetR2RMLJenaModelParser.java

示例8: object

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private String object(RDFNode node) {
    if (node.isLiteral()) {
        Literal lit = node.asLiteral();
        String text = lit.getString();
        String lang = lit.getLanguage();
        String type = lit.getDatatypeURI();

        if (lang == null || "".equals(lang)) {
            lang = "";
        } else {
            lang = " xml:lang='" + escapeXml(lang) + "'";
        }

        if ("".equals(lang)) {
            if (type == null) {
                type = "http://www.w3.org/2001/XMLSchema#string";
            }
            type = " datatype='" + escapeXml(type) + "'";
        } else {
            type = "";
        }

        return "<sem:object" + type + lang + ">" + escapeXml(text) + "</sem:object>";
    } else if (node.isAnon()) {
        return "<sem:object>http://marklogic.com/semantics/blank/" + Long.toHexString(
                fuse(scramble((long)node.hashCode()),fuse(scramble(milliSecs),randomValue)))
                +"</sem:object>";
    } else {
        return "<sem:object>" + escapeXml(node.toString()) + "</sem:object>";
    }
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:32,代码来源:RDFReader.java

示例9: 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();
	}
}
 
开发者ID:phenopackets,项目名称:phenopacket-reference-implementation,代码行数:10,代码来源:RdfReader.java

示例10: 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());
	}
}
 
开发者ID:Web-of-Building-Data,项目名称:Ifc2Rdf,代码行数:8,代码来源:RdfUtils.java

示例11: getShortStringWithType

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public static String getShortStringWithType(RDFNode node) {
	if (node.isLiteral()) {
		return node.asLiteral().getLexicalForm();
	} else {
		return getShortStringWithType(node.asResource());
	}
}
 
开发者ID:Web-of-Building-Data,项目名称:Ifc2Rdf,代码行数:8,代码来源:RdfUtils.java

示例12: convertIntoTable

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private static StringMatrix convertIntoTable(
		PrefixMapping prefixMap, ResultSet results) {
	StringMatrix table = new StringMatrix();
	int rowCount = 0;
	while (results.hasNext()) {
		rowCount++;
		QuerySolution soln = results.nextSolution();
		Iterator<String> varNames = soln.varNames();
		while (varNames.hasNext()) {
			String varName = varNames.next();
			int colCount = -1;
			if (table.hasColumn(varName)) {
				colCount = table.getColumnNumber(varName);
			} else {
				colCount = table.getColumnCount() + 1;
				table.setColumnName(colCount, varName);
			}
			RDFNode node = soln.get(varName);
			if (node != null) {
				if (node.isResource()) {
					Resource resource = (Resource)node;
					table.set(rowCount, colCount,
						resource.getURI()
					);
				} else if (node.isLiteral()) {
					Literal literal = (Literal)node;
					table.set(rowCount, colCount, "" + literal.getValue());
				}
			}
		}
	}
	return table;
}
 
开发者ID:wikipathways,项目名称:GPML2RDF,代码行数:34,代码来源:SPARQLHelper.java

示例13: apply

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Override
public Optional<String> apply(final Statement input) {
	final RDFNode object=input.getObject();
	if(object.isLiteral()) {
		final Literal literal=object.asLiteral();
		if(literal.getDatatypeURI()==null || "http://www.w3.org/2001/XMLSchema#string".equals(literal.getDatatypeURI())) {
			return Optional.of(literal.getLexicalForm());
		}
	}
	this.report.warn("Discarding invalid value for property %s: not a String Literal (%s)",input.getPredicate().getURI(),object);
	return Optional.absent();
}
 
开发者ID:SmartDeveloperHub,项目名称:sdh-vocabulary,代码行数:13,代码来源:Catalog.java

示例14: filter

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Override
public boolean filter(Resource rsrc)
{
    StmtIterator iter = rsrc.listProperties(rsrc.getModel().getProperty(_property));
    while ( iter.hasNext() )
    {
        RDFNode obj = iter.next().getObject();
        boolean res = false;
             if ( obj.isLiteral()     ) { res = filterLiteral(obj.asLiteral());   }
        else if ( obj.isURIResource() ) { res = filterResource(obj.asResource()); }

        if ( res ) { return true; }
    }
    return false;
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:16,代码来源:EntityFilter.java

示例15: copyFromTdb

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void copyFromTdb( Dataset dataset ) throws RepositoryException {
	ValueFactory vf = rc.getValueFactory();

	if ( dataset.supportsTransactions() ) {
		dataset.begin( ReadWrite.READ );
	}

	// Get model inside the transaction
	Model model = dataset.getDefaultModel();
	StmtIterator si = model.listStatements();

	try {
		rc.begin();
		while ( si.hasNext() ) {
			Statement stmt = si.next();
			com.hp.hpl.jena.rdf.model.Resource rsr = stmt.getSubject();
			Property pred = stmt.getPredicate();
			RDFNode val = stmt.getObject();
			Node valnode = val.asNode();
			
			Resource sub;
			try {
				sub = ( rsr.isAnon()
						? vf.createBNode( valnode.getBlankNodeLabel() )
						: vf.createURI( rsr.toString() ) );
			}
			catch ( UnsupportedOperationException uoo ) {
				log.warn( uoo, uoo );
				continue;
			}
			
			URI pred2 = vf.createURI( pred.toString() );
			Value val2;

			if ( val.isLiteral() ) {
				Literal lit = val.asLiteral();
				String dtstr = lit.getDatatypeURI();
				URI dt = ( null == dtstr ? null : vf.createURI( dtstr ) );
				String langstr = lit.getLanguage();

				if ( null == dt ) {
					if ( langstr.isEmpty() ) {
						val2 = vf.createLiteral( lit.toString() );
					}
					else {
						val2 = vf.createLiteral( lit.toString(), langstr );
					}
				}
				else {
					val2 = vf.createLiteral( lit.toString(), dt );
				}
			}
			else {
				if ( val.isAnon() ) {
					val2 = vf.createBNode( valnode.getBlankNodeLabel() );
				}
				else {
					val2 = vf.createURI( val.toString() );
				}
			}
			rc.add( sub, pred2, val2 );
		}
		rc.commit();
	}
	catch ( RepositoryException re ) {
		rc.rollback();
		throw re;
	}
	finally {
		if ( dataset.supportsTransactions() ) {
			dataset.end();
		}
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:75,代码来源:JenaEngine.java


注:本文中的com.hp.hpl.jena.rdf.model.RDFNode.isLiteral方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。