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


Java Literal类代码示例

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


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

示例1: buildNext

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
@Override
protected Indexable buildNext(Statement statement) {
    InstanceEntity instanceEntity = createInstance(applyNS(statement.getSubject().getURI()));
    PropertyEntity propertyEntity = createProperty(applyNS(statement.getPredicate().getURI()));

    LabeledEntity labeledEntity;

    if (!statement.getObject().isLiteral()) {
        //Is created as an instance but can be changed to a class down on the workflow in EntityClassifierProcessor.
        labeledEntity = createInstance(applyNS(statement.getObject().asResource().getURI()));
    } else {
        Literal literal = statement.getObject().asLiteral();
        String dataType = literal.getDatatypeURI();
        String langTag = literal.getLanguage();
        String value = literal.getLexicalForm();
        labeledEntity = new ValueEntity(value, dataType, langTag);
    }


    return new Indexable(new Fact(kbId, instanceEntity, propertyEntity, labeledEntity), kbId);
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:22,代码来源:FactIterator.java

示例2: renderHierarchy

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
protected static void renderHierarchy(PrintStream out, OntClass cls, List<Object> occurs, int depth) {
  renderClassDescription(out, cls, depth);
  out.println();

  // recurse to the next level down
  if (cls.canAs(OntClass.class) && !occurs.contains(cls)) {
    for (Iterator<?> i = cls.listSubClasses(true); i.hasNext(); ) {
      OntClass sub = (OntClass) i.next();

      // we push this expression on the occurs list before we recurse
      occurs.add(cls);
      renderHierarchy(out, sub, occurs, depth + 1);
      occurs.remove(cls);
    }
    for (Iterator<?> i = cls.listInstances(); i.hasNext(); ) {
      Individual individual = (Individual) i.next();
      renderURI(out, individual.getModel(), individual.getURI());
      out.print(" [");
      for (Iterator<?> j = individual.listLabels(null); j.hasNext(); ) {
        out.print(((Literal) j.next()).getString() + ", ");
      }
      out.print("] ");
      out.println();
    }
  }
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:27,代码来源:LocalOntology.java

示例3: renderClassDescription

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public static void renderClassDescription(PrintStream out, OntClass c, int depth) {
  indent(out, depth);

  if (c.isRestriction()) {
    renderRestriction(out, (Restriction) c.as(Restriction.class));
  } else {
    if (!c.isAnon()) {
      out.print("Class ");
      renderURI(out, c.getModel(), c.getURI());

      out.print(c.getLocalName());

      out.print(" [");
      for (Iterator<?> i = c.listLabels(null); i.hasNext(); ) {
        out.print(((Literal) i.next()).getString() + ", ");
      }
      out.print("] ");
    } else {
      renderAnonymous(out, c, "class");
    }
  }
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:23,代码来源:LocalOntology.java

示例4: getLabelFromLinkedData

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
/**
   * Dereference the IRI and look for label property value.
   * @param iri the IRI
   * @return the label if exist, otherwise <code>null</code>
   */
  private String getLabelFromLinkedData(String iri){
  	logger.debug("Get label for " + iri + " from Linked Data...");
  	
try {
	// 1. get triples for the IRI by sending a Linked Data request
	Model model = uriDereferencer.dereference(iri);
	
	// 2. check if we find a label in the triples
	for (String labelProperty : labelProperties) {
		for(Statement st : model.listStatements(model.getResource(iri), model.getProperty(labelProperty), (RDFNode)null).toList()){
			Literal literal = st.getObject().asLiteral();
			
			// language check
			String language = literal.getLanguage();
			if(language != null && language.equals(this.language)){
				return literal.getLexicalForm();
			}
		}
	}
} catch (DereferencingFailedException e) {
	logger.error(e.getMessage(), e);
}
  	return null;
  }
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:30,代码来源:DefaultIRIConverter.java

示例5: getCount

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public static int getCount(String q, Model m) {
    Query query = QueryFactory.create(q);
    QueryExecution queryExec = QueryExecutionFactory.create(query, m);
    ResultSet rs = queryExec.execSelect();
    String vName = "";
    for (String v: rs.getResultVars()) {
        if (v.contains("count")) {
            vName = v;
            break;
        }
    }
    
    while (rs.hasNext()) {
        QuerySolution s = rs.nextSolution();
        Literal c = s.getLiteral(vName);
        queryExec.close();
        return c.getInt();
    }   
    queryExec.close();
    return 0;
}
 
开发者ID:albangaignard,项目名称:EDAMetrics,代码行数:22,代码来源:Queries.java

示例6: getTypedContent

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public Literal getTypedContent(String con) {
	try {

		return ResourceFactory.createTypedLiteral(Double.valueOf(con));
		// return "\"" + Double.valueOf(con) + "\"^^xsd:double";
	} catch (java.lang.NumberFormatException e) {
		try {
			return ResourceFactory.createTypedLiteral(Float.valueOf(con));
			// return "\"" + Float.valueOf(con) + "\"^^xsd:float";
		} catch (Exception e2) {
			return ResourceFactory.createTypedLiteral(String.valueOf(con));
			// return "\"" + con + "\"^^xsd:string";
		}
	}

}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:17,代码来源:OneM2MContentInstanceMapper.java

示例7: getBooleanFromLiteral

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
private static boolean getBooleanFromLiteral(Literal literal) throws DatatypeFormatException {
    try {
        return literal.getBoolean();
    } catch (DatatypeFormatException e) {
        // This litral is not a boolean. Try to understand it
        String lexicalForm = literal.getLexicalForm().toLowerCase();
        boolean result;
        if ("true".equals(lexicalForm) || "1".equals(lexicalForm)) {
            result = true;
        } else if ("false".equals(lexicalForm) || "0".equals(lexicalForm)) {
            result = false;
        } else {
            throw e;
        }
        LOGGER.warn("Interpreted the non-boolean literal {} as {}. This should be avoided.", literal.toString(),
                result);
        return result;
    }
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:20,代码来源:RdfModelHelper.java

示例8: DBpediaGenderDictionary

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public DBpediaGenderDictionary() {
	Model model = ModelFactory.createDefaultModel();

	Literal maleLit = model.createLiteral(VALUE_MALE, "en");
	Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");

	RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
	StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
	while (iter.hasNext()) {
		Statement st = iter.next();
		Literal lit = st.getObject().asLiteral();
		if (lit.equals(maleLit)) {
			male.add(st.getSubject().getURI());
		} else if (lit.equals(femaleLit)) {
			female.add(st.getSubject().getURI());
		}
	}
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:19,代码来源:DBpediaGenderDictionary.java

示例9: createCardinalityRestriction

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public OntClass createCardinalityRestriction(OntProperty p,
		int cardinality) {

	/*
	 * NOTE: the create(Min|Max)CardinalityRestriction(...) methods from
	 * Jena - or the turtle serialization - encodes the cardinality as an
	 * xsd:int, which should be an xsd:nonNegativeInteger according to
	 * https://www.w3.org/TR/owl2-mapping-to-rdf/
	 * 
	 * That's why we create and set the typed literal that represents the
	 * cardinality ourselves.
	 */

	OntClass restriction = this.ontmodel.createCardinalityRestriction(null,
			p, cardinality);
	restriction.removeAll(OWL.cardinality);
	Literal cardAsNonNegativeInteger = ontmodel.createTypedLiteral(
			cardinality,
			"http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
	restriction.addLiteral(OWL.cardinality, cardAsNonNegativeInteger);
	return restriction;
}
 
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:23,代码来源:OntologyModel.java

示例10: createMinCardinalityRestriction

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public OntClass createMinCardinalityRestriction(OntProperty p,
		int cardinality) {

	/*
	 * NOTE: the create(Min|Max)CardinalityRestriction(...) methods from
	 * Jena - or the turtle serialization - encodes the cardinality as an
	 * xsd:int, which should be an xsd:nonNegativeInteger according to
	 * https://www.w3.org/TR/owl2-mapping-to-rdf/
	 * 
	 * That's why we create and set the typed literal that represents the
	 * cardinality ourselves.
	 */

	OntClass restriction = this.ontmodel
			.createMinCardinalityRestriction(null, p, cardinality);
	restriction.removeAll(OWL.minCardinality);
	Literal cardAsNonNegativeInteger = ontmodel.createTypedLiteral(
			cardinality,
			"http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
	restriction.addLiteral(OWL.minCardinality, cardAsNonNegativeInteger);
	return restriction;
}
 
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:23,代码来源:OntologyModel.java

示例11: createMaxCardinalityRestriction

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public OntClass createMaxCardinalityRestriction(OntProperty p,
		int cardinality) {

	/*
	 * NOTE: the create(Min|Max)CardinalityRestriction(...) methods from
	 * Jena - or the turtle serialization - encodes the cardinality as an
	 * xsd:int, which should be an xsd:nonNegativeInteger according to
	 * https://www.w3.org/TR/owl2-mapping-to-rdf/
	 * 
	 * That's why we create and set the typed literal that represents the
	 * cardinality ourselves.
	 */

	OntClass restriction = this.ontmodel
			.createMaxCardinalityRestriction(null, p, cardinality);
	restriction.removeAll(OWL.maxCardinality);
	Literal cardAsNonNegativeInteger = ontmodel.createTypedLiteral(
			cardinality,
			"http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
	restriction.addLiteral(OWL.maxCardinality, cardAsNonNegativeInteger);
	return restriction;
}
 
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:23,代码来源:OntologyModel.java

示例12: getNameValueMap

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
protected Map<String, String> getNameValueMap(Resource resource, UriTemplateParser parser)
   {
if (resource == null) throw new IllegalArgumentException("Resource cannot be null");
       if (parser == null) throw new IllegalArgumentException("UriTemplateParser cannot be null");

Map<String, String> nameValueMap = new HashMap<>();

       List<String> names = parser.getNames();
for (String name : names)
{
    Literal literal = getLiteral(resource, name);
    if (literal != null)
	nameValueMap.put(name, literal.getString());
}

       return nameValueMap;
   }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:18,代码来源:Skolemizer.java

示例13: assertEquals

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
@Override
public void assertEquals(RDFNode o1, RDFNode o2) {

	RdfNodeTypeEnum type1 = RdfNodeTypeEnum.getType(o1);
	RdfNodeTypeEnum type2 = RdfNodeTypeEnum.getType(o2);
	Assert.assertEquals(type1, type2);
	
	if (type1.equals(RdfNodeTypeEnum.Literal)) {
		final Asserter<Literal> literalAsserter = new LiteralAsserter();
		literalAsserter.assertEquals(o1.asLiteral(), o2.asLiteral());
	} else if (type1.equals(RdfNodeTypeEnum.Uri)) {
		Assert.assertEquals(o1.asResource().getURI(), o2.asResource().getURI());
	} else {
		assert(o1.isAnon());
		
		if (!ignoreAnonIds) {
			Assert.assertEquals(o1.asResource().getId().toString(), o2.asResource().getId().toString());
		}
		
		if (!ignoreAnonProperties) {
			final Asserter<StmtIterator> stmtIteratorAsserter = new StmtIteratorAsserter(true, ignoreAnonIds, ignoreAnonProperties);
			stmtIteratorAsserter.assertEquals(o1.asResource().listProperties(), o2.asResource().listProperties());
		}				
	}
}
 
开发者ID:Web-of-Building-Data,项目名称:drumbeat-ifc2ld,代码行数:26,代码来源:RdfAsserter.java

示例14: toOWL

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
public static Resource toOWL(OntModel ont, String type) {
	if (type==null) return null;
	if (type.equals(schema.anySimpleType)) return RDFS.Literal;
	else if (type.equals(schema.ENTITY)) return ont.getResource(RDF.getURI()+"XMLLiteral");
	else if ( // structured type
		type.equals(schema.XSD_URI+"#anyType") ||
		type.equals(schema.XSD_URI+"#duration")) {
		return null;
	}
	// list type
	else if (type.equals(schema.XSD_URI+"#IDREFS"))
		return RDF.List;
	else if (type.equals(schema.XSD_URI+"#ENTITIES"))
		return toList(ont,type,schema.XSD_URI+"#ENTITY");
	else if (type.equals(schema.XSD_URI+"#NMTOKENS"))
		return toList(ont,type,schema.XSD_URI+"#NMTOKEN");
		
	else if ( // object reference
		type.equals(schema.XSD_URI+"#IDREF") ||
		type.equals(schema.XSD_URI+"#QName") ||
		type.equals(schema.XSD_URI+"#NOTATION")) {
		return null;
	}		
	else return ont.getResource(type);
}
 
开发者ID:stevebattle,项目名称:Gloze,代码行数:26,代码来源:schema.java

示例15: noSchemaToRDF

import org.apache.jena.rdf.model.Literal; //导入依赖的package包/类
/** only returns the default ns if defined */

public static void noSchemaToRDF(Resource subject, Attr attr, Context ctx) {
	if (attr.getNodeName().startsWith("xmlns")) {
		// set the namespace definition on the model
		String name = attr.getNodeName();
		String ns = attr.getNodeValue();
		String prefix = "";
		if (name.indexOf(":")>=0) {
			prefix = name.substring("xmlns:".length());
			if (!ns.equals(XMLBean.XML) && !ns.equals(schema.XSI)) 
				XMLBean.addPrefixes(prefix,ns,ctx.getModel());
		}
		return;					
	}
	Literal l = ctx.getModel().createLiteral(attr.getValue());
	String u = XMLBean.expandQName(attr, ctx);
	if (!u.startsWith(schema.XSI) && !u.startsWith(XMLBean.XML)) { 
		// not a schema instance or XML property
		Property p = ctx.getModel().createProperty(u);
		subject.addProperty(p,l);
	}
	XMLBean.addPrefixes(attr.getPrefix(), attr.getNamespaceURI(), ctx.getModel());
}
 
开发者ID:stevebattle,项目名称:Gloze,代码行数:25,代码来源:XMLBean.java


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