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


Java Literal类代码示例

本文整理汇总了Java中com.hp.hpl.jena.rdf.model.Literal的典型用法代码示例。如果您正苦于以下问题:Java Literal类的具体用法?Java Literal怎么用?Java Literal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: asSesameLiteral

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
 * Convert the given Jena Literal to a Sesame Literal
 * @param theLiteral the Jena Literal to convert
 * @return the Jena Literal as a Sesame Literal
 */
public static org.openrdf.model.Literal asSesameLiteral(Literal theLiteral) {
    if (theLiteral == null) {
        return null;
    }
    else if (theLiteral.getLanguage() != null && !theLiteral.getLanguage().equals("")) {
        return FACTORY.createLiteral(theLiteral.getLexicalForm(),
                theLiteral.getLanguage());
    }
    else if (theLiteral.getDatatypeURI() != null) {
        return FACTORY.createLiteral(theLiteral.getLexicalForm(),
                FACTORY.createURI(theLiteral.getDatatypeURI()));
    }
    else {
        return FACTORY.createLiteral(theLiteral.getLexicalForm());
    }
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:22,代码来源:JenaSesameUtils.java

示例2: asJenaLiteral

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
 * Convert a Sesame Literal to a Jena Literal
 * @param theLiteral the Sesame literal
 * @return the sesame literal converted to Jena
 */
public static com.hp.hpl.jena.rdf.model.Literal asJenaLiteral(org.openrdf.model.Literal theLiteral) {
    if (theLiteral == null) {
        return null;
    }
    else if (theLiteral.getLanguage() != null) {
        return mInternalModel.createLiteral(theLiteral.getLabel(),
                theLiteral.getLanguage());
    }
    else if (theLiteral.getDatatype() != null) {
        return mInternalModel.createTypedLiteral(theLiteral.getLabel(),
                theLiteral.getDatatype().toString());
    }
    else {
        return mInternalModel.createLiteral(theLiteral.getLabel());
    }
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:22,代码来源:JenaSesameUtils.java

示例3: getSubclass

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
public OntoRecord getSubclass(String resourceURI, String lang){
    
    StmtIterator iter1 = model.listStatements( new SimpleSelector(ResourceFactory.createResource(resourceURI), ResourceFactory.createProperty("http://www.w3.org/2000/01/rdf-schema#subClassOf"),  (RDFNode)null));
    OntoRecord record = new OntoRecord();
    StmtIterator iter2;
    
    while(iter1.hasNext()) {
        record.setUri(iter1.next().getObject().toString());
        iter2 = model.listStatements( new SimpleSelector(ResourceFactory.createResource(record.getUri()), ResourceFactory.createProperty("http://www.w3.org/2000/01/rdf-schema#label"),  (RDFNode)null));
        
        while(iter2.hasNext()){
            Literal res = (Literal) iter2.next().getObject();                
            String tmpLang = res.getLanguage();
            
            if( tmpLang.equals("en") ){
                record.setLabel(res.getString());
                return record;
                
            }
        }
    }
    return null;        
}
 
开发者ID:entityclassifier-eu,项目名称:entityclassifier-core,代码行数:24,代码来源:DBpediaOntologyManager.java

示例4: copyAllowedProperties

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
protected void copyAllowedProperties(Model readModel, Model model, Set<Resource> classes,
        Set<Property> allowedProperties) {
    StmtIterator stmtIterator = readModel.listStatements();
    Statement s;
    Literal label;
    while (stmtIterator.hasNext()) {
        s = stmtIterator.next();
        if (classes.contains(s.getSubject()) && allowedProperties.contains(s.getPredicate())
                && (!s.getObject().isAnon())) {
            if (s.getPredicate().equals(RDFS.label)) {
                label = s.getObject().asLiteral();
                if (label.getLanguage().equals("en")) {
                    model.add(s.getSubject(), RDFS.label,
                            model.createLiteral(label.getString().toLowerCase(), "en"));
                }
            } else {
                model.add(s);
            }
        }
    }
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:22,代码来源:DolceClassHierarchyLoader.java

示例5: parseN3

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
private static void parseN3(GrabMappingsHandler handler, String infileurl) {
  Model model = ModelFactory.createDefaultModel();
  model.read(infileurl, "N3");

  AResourceImpl sub = new AResourceImpl();
  AResourceImpl pred = new AResourceImpl();
  AResourceImpl objres = new AResourceImpl();
  ALiteralImpl objlit = new ALiteralImpl();
  StmtIterator it = model.listStatements();
  while (it.hasNext()) {
    Statement stmt = it.nextStatement();
    RDFNode object = stmt.getObject();
    sub.setResource(stmt.getSubject());
    pred.setResource(stmt.getPredicate());
    
    if (object instanceof Literal) {
      objlit.setLiteral((Literal) object);
      handler.statement(sub, pred, objlit);
    } else {
      objres.setResource((Resource) object);
      handler.statement(sub, pred, objres);
    }
  }
}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:25,代码来源:RDFIntroSpector.java

示例6: writeStatement

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的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

示例7: fixLanguage

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的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

示例8: binding

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的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

示例9: literal

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
private void literal(Literal l) {
    atts.clear();
    try {
        String s = l.getLexicalForm();
        String lang = l.getLanguage();
        String dt = l.getDatatypeURI();
        // Literal with lang?
        if (lang != null && lang.length() != 0) {
            atts.addAttribute(ARQConstants.XML_NS, "lang", "xml:lang", "CDATA", lang);
        }
        // Literal with datatype?
        if (dt != null && dt.length() != 0) {
            atts.addAttribute(dfNamespace, dfAttrDatatype, dfAttrDatatype, "CDATA", dt);
        }
        handler.startElement(dfNamespace, dfLiteral, dfLiteral, atts);
        handler.characters(s.toCharArray(), 0, s.length());
        handler.endElement(dfNamespace, dfLiteral, dfLiteral);
    } catch (SAXException ex) {
    }
}
 
开发者ID:ljo,项目名称:exist-sparql,代码行数:21,代码来源:JenaResultSet2Sax.java

示例10: getGeoLocation

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
  * Gets and returns the geolocation of a POI
  * @param resource
  * @return
  */
 private static Literal getGeoLocation(String resource){
 	
 	Literal geoLocation;
 	
 	String sparqlquery= "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> \n"			
				+ "select distinct ?geolocation where {" 
				+ "<"+resource+"> geo:geometry ?geolocation.}\n"
				+ "LIMIT 1 ";
 	Query query = QueryFactory.create(sparqlquery);
  QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
  ResultSet results = qexec.execSelect();
  if (results.hasNext() ){ 				
QuerySolution soln = results.nextSolution();
geoLocation = soln.getLiteral("geolocation");
   qexec.close();
   return geoLocation;
  }
  else {
   qexec.close();
  	return null;
  }
 }
 
开发者ID:Localizr,项目名称:Localizr,代码行数:28,代码来源:GeoNamesRecommendation.java

示例11: graphNodeToSadlNode

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
 * Convert a Jena graph Node to a SADL model Node
 * @param node
 * @return
 */
protected Node graphNodeToSadlNode(com.hp.hpl.jena.graph.Node node) {
	if (node instanceof Node_Variable) {
		return new VariableNode(((Node_Variable)node).getName().substring(1));
	}
	else if (node instanceof Node_URI) {
		return new NamedNode(((Node_URI)node).getURI());
	}
	else if (node instanceof Node_Literal){
		com.ge.research.sadl.model.gp.Literal lit = new com.ge.research.sadl.model.gp.Literal();
		lit.setValue(((Node_Literal)node).getLiteral().getValue());
		return lit;
	}
	else {
		return new NamedNode(node.toString());
	}
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:22,代码来源:JenaReasonerPlugin.java

示例12: getMappingPrefix

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
private synchronized String getMappingPrefix(String modelName) {
	Resource publicUri = getMappingModel().createResource(modelName);
	StmtIterator sitr = getMappingModel().listStatements(null,
			publicUrlProp, publicUri);
	if (sitr.hasNext()) {
		Resource ontSpec = sitr.nextStatement().getSubject();
		Statement stmt = ontSpec.getProperty(prefixProp);
		if (stmt != null) {
			RDFNode val = stmt.getObject();
			if (val.isLiteral()) {
				return ((Literal) val).getLexicalForm();
			}
		}
	}
	return null;
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:17,代码来源:ConfigurationManagerForEditing.java

示例13: getTranslatorForReasoner

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
@Override
public ITranslator getTranslatorForReasoner(String reasonerName) throws ConfigurationException {
	if (getConfigModel() != null) {
		Resource subject = getConfigModel().getResource("http://com.ge.research.sadl.configuration#" + reasonerName);
		if (subject != null) {
			Property predicate = getConfigModel().getProperty("http://com.ge.research.sadl.configuration#translatorClassName");
			if (predicate != null) {
				StmtIterator sitr = getConfigModel().listStatements(subject, predicate, (RDFNode)null);
				if (sitr.hasNext()) {
					RDFNode rcls = sitr.next().getObject();
					if (rcls instanceof Literal) {
						String clsName = rcls.asLiteral().getString();
						return getTranslatorInstanceByClass(clsName);
					}
				}
			}
		}
		
	}
	return null;
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:22,代码来源:ConfigurationManager.java

示例14: getTranslatorClassName

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
/**
 * Method to return the fully qualified name of the class for the current ITranslator as specified in the configuration.
 * @return
 * @throws ConfigurationException 
 */
public String getTranslatorClassName() throws ConfigurationException {
	IReasoner reasonerInst = getReasonerInstance();
	Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory());
		StmtIterator sitr = getConfigModel().listStatements(reasonerCategory, 
			getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null);
       if (sitr.hasNext()) { 
       	RDFNode clsnmnode = sitr.nextStatement().getObject();
       	if (clsnmnode instanceof Literal) {
       		return ((Literal)clsnmnode).getValue().toString();
       	}
       }
       ITranslator translator = getTranslator();
	if (translator != null) {
		return translator.getClass().getCanonicalName();
	}
	throw new ConfigurationException("Unable to get current translator for unknown reason.");
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:23,代码来源:ConfigurationManager.java

示例15: getTranslatorInstance

import com.hp.hpl.jena.rdf.model.Literal; //导入依赖的package包/类
private ITranslator getTranslatorInstance() throws ConfigurationException {
	String translatorClassName = null;
	if (getConfigModel() != null) {
		IReasoner reasonerInst = getReasonerInstance();
		Resource reasonerCategory = getConfigModel().getResource(CONFIG_NAMESPACE + reasonerInst.getConfigurationCategory());
		StmtIterator sitr = getConfigModel().listStatements(reasonerCategory, 
				getConfigModel().getProperty(pTRANSLATOR_CLASSNAME), (RDFNode)null);
		if (sitr.hasNext()) {
			RDFNode cnobj = sitr.next().getObject();
			if (cnobj instanceof Literal) {
				translatorClassName = ((Literal)cnobj).getLexicalForm();
			}
		}
	}
	if (translatorClassName == null) {
		translatorClassName = DEFAULT_TRANSLATOR;
	}
	return getTranslatorInstanceByClass(translatorClassName);
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:20,代码来源:ConfigurationManager.java


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