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


Java RDFNode.asLiteral方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: extract

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public void extract(Model src, Model trg)
{
    trg.setNsPrefix("skos", SKOS_NS);
    Property pType = trg.createProperty(RDF_TYPE);
    Property pPLbl = trg.createProperty(SKOS_PREF_LABEL);
    Property pNote = trg.createProperty(SKOS_NOTE);
    Property pInS  = trg.createProperty(SKOS_IN_SCHEME);

    Resource rCpt  = trg.createResource(SKOS_CONCEPT);
    Resource rSch  = trg.createResource(SKOS_CONCEPT_SCHEME);

    Resource scheme = trg.createResource(_base + "ConceptScheme");
    scheme.addProperty(pType, rSch);

    for ( String pName : PROPERTIES )
    {
        Property p = src.getProperty(pName);
        StmtIterator iter = src.listStatements(null, p, (RDFNode)null);
        while ( iter.hasNext() )
        {
            Statement stmt = iter.nextStatement();
            RDFNode   node = stmt.getObject();
            if ( node.isResource() ) { continue; }

            Literal  l    = node.asLiteral();
            Resource rsrc = trg.createResource(createURI(l));
            rsrc.addProperty(pType, rCpt);
            rsrc.addProperty(pPLbl, l.getString(), l.getLanguage());
          //rsrc.addProperty(pNote, stmt.getSubject().getURI());
            rsrc.addProperty(pNote, stmt.getSubject());
            rsrc.addProperty(pInS , scheme);
        }
    }
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:35,代码来源:SKOSExtractor.java

示例6: 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

示例7: isTypeOf

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
boolean isTypeOf(RDFNode node) {
	if (!node.isLiteral()) return false;
	Literal l = node.asLiteral();
	return XSD.xstring.getURI().equals(l.getDatatypeURI())
			|| (l.getDatatypeURI() == null && "".equals(l.getLanguage()));
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:7,代码来源:R2RMLReader.java

示例8: object

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void object(TreeWriter tree, 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 = null;
        } else {
            lang = escapeXml(lang);
        }

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

        tree.addStartElement(sem_object);
        if (lang != null) {
            tree.addAttribute(XProcConstants.xml_lang, lang);
        }
        if (type != null) {
            tree.addAttribute(_datatype, type);
        }
        tree.startContent();
        tree.addText(escapeXml(text));
        tree.addEndElement();
    } else if (node.isAnon()) {
        String uri = "http://marklogic.com/semantics/blank/" + Long.toHexString(
                fuse(scramble((long)node.hashCode()),fuse(scramble(milliSecs),randomValue)));

        tree.addStartElement(sem_object);
        tree.startContent();
        tree.addText(uri);
        tree.addEndElement();
    } else {
        tree.addStartElement(sem_object);
        tree.startContent();
        tree.addText(escapeXml(node.toString()));
        tree.addEndElement();
    }
}
 
开发者ID:ndw,项目名称:xmlcalabash1-rdf,代码行数:48,代码来源:RDFStep.java

示例9: runSelectionQuery

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public SelectionResult runSelectionQuery(Op op) {

		SelectionResult result = new SelectionResult();

		ResultSetRewindable results = jenaService.runExternalOp(op);
		
		results.reset();
		
		for (; results.hasNext();) {
			QuerySolution soln = results.next();

			RDFNode predicate = soln.get("predicate");
			RDFNode object = soln.get("value");

			Literal literal = object.asLiteral();
			if (!literal.getString().isEmpty()) {
				result.addResult(predicate, literal);
			}
		}

		return result;
	}
 
开发者ID:christoff-buerger,项目名称:reneviz,代码行数:23,代码来源:SparqlService.java


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