本文整理汇总了Java中org.apache.jena.datatypes.xsd.XSDDatatype类的典型用法代码示例。如果您正苦于以下问题:Java XSDDatatype类的具体用法?Java XSDDatatype怎么用?Java XSDDatatype使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSDDatatype类属于org.apache.jena.datatypes.xsd包,在下文中一共展示了XSDDatatype类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverterPortuguese conv = new LiteralConverterPortuguese(
new DefaultIRIConverterPortuguese(SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123",
// null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1879-03-14^^http://www.w3.org/2001/XMLSchema#date").getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
示例2: main
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverter conv = new LiteralConverter(new DefaultIRIConverter(
SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123", null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
示例3: main
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverterFrench conv = new LiteralConverterFrench(
new DefaultIRIConverterPortuguese(SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123",
// null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1879-03-14^^http://www.w3.org/2001/XMLSchema#date").getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
示例4: testConvertDate
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
/**
* Test method for
* {@link org.aksw.triple2nl.converter.sparql2nl.naturallanguagegeneration.LiteralConverter#convert(org.apache.jena.rdf.model.Literal)}.
*/
@Test
public void testConvertDate() {
LiteralLabel lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
String convert = conv.convert(lit);
System.out.println(lit + " --> " + convert);
assertEquals("June 27, 1869", convert); // would be with June 27, 1869
// in US
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1989", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
示例5: makeSampleModel
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
private static Model makeSampleModel() {
String BASE = "http://example/";
Model model = ModelFactory.createDefaultModel();
model.setNsPrefix("", BASE);
Resource r1 = model.createResource(BASE + "r1");
Resource r2 = model.createResource(BASE + "r2");
Property p1 = model.createProperty(BASE + "p");
Property p2 = model.createProperty(BASE + "p2");
RDFNode v1 = model.createTypedLiteral("1", XSDDatatype.XSDinteger);
RDFNode v2 = model.createTypedLiteral("2", XSDDatatype.XSDinteger);
r1.addProperty(p1, v1).addProperty(p1, v2);
r1.addProperty(p2, v1).addProperty(p2, v2);
r2.addProperty(p1, v1).addProperty(p1, v2);
return model;
}
示例6: addKpi
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
private static Resource addKpi(KeyPerformanceIndicatorBean kpi, Model model) {
Resource kpiResource = model.getResource(kpi.getId());
model.add(kpiResource, RDF.type, HOBBIT.KPI);
if ((kpi.getName() != null) && (!kpi.getName().equals(kpi.getId()))) {
model.add(kpiResource, RDFS.label, kpi.getName(), "en");
}
if ((kpi.getDescription() != null) && (!kpi.getDescription().equals(kpi.getId()))) {
model.add(kpiResource, RDFS.comment, kpi.getDescription(), "en");
}
if (kpi.getDatatype() != null) {
XSDDatatype datatype = datatypeToXsd(kpi.getDatatype());
if (datatype != null) {
model.add(kpiResource, RDFS.range, model.getResource(datatype.getURI()));
}
} if (kpi.getRanking() != null) {
model.add(kpiResource, HOBBIT.ranking, model.getResource(kpi.getRanking()));
}
return kpiResource;
}
示例7: datatypeToXsd
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public static XSDDatatype datatypeToXsd(Datatype datatype) {
switch (datatype) {
case BOOLEAN:
return XSDDatatype.XSDboolean;
case DECIMAL:
return XSDDatatype.XSDdecimal;
case DOUBLE:
return XSDDatatype.XSDdouble;
case FLOAT:
return XSDDatatype.XSDfloat;
case INTEGER:
return XSDDatatype.XSDint;
case STRING:
return XSDDatatype.XSDstring;
case UNSIGNED_INT:
return XSDDatatype.XSDunsignedInt;
default:
return null;
}
}
示例8: main
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public static void main(String[] args) {
LiteralConverter conv = new LiteralConverter(
new DefaultIRIConverter(SparqlEndpoint.getEndpointDBpediaLiveAKSW()));
LiteralLabel lit;// = NodeFactory.createLiteralNode("123",
// null,"http://dbpedia.org/datatypes/squareKilometre").getLiteral();
// System.out.println(lit);
// System.out.println(conv.convert(lit));
lit = NodeFactory.createLiteral("1869-06-27", null, XSDDatatype.XSDdate).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("1914-01-01T00:00:00+02:00", null, XSDDatatype.XSDgYear).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
lit = NodeFactory.createLiteral("--04", null, XSDDatatype.XSDgMonth).getLiteral();
System.out.println(lit + " --> " + conv.convert(lit));
}
示例9: exec
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
@Override
public NodeValue exec(NodeValue timeStampValue) {
BigInteger timeStamp;
if (timeStampValue == null || !timeStampValue.isInteger()) {
throw new ExprEvalException("The NodeValue " + timeStampValue + " MUST be an integer."
);
} else {
timeStamp = timeStampValue.getInteger();
}
if (timeStamp.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) != -1) {
throw new ExprEvalException("The NodeValue " + timeStamp + " MUST be less than the biggest long value."
);
} else if (timeStamp.signum() != 1) {
throw new ExprEvalException("The NodeValue " + timeStamp + " MUST be positive."
);
}
Timestamp stamp = new Timestamp(timeStamp.longValue());
Date date = new Date(stamp.getTime());
Node node = NodeFactory.createLiteral(df.format(date), XSDDatatype.XSDdateTime);
return new NodeValueNode(node);
}
示例10: toRDFNode
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public static RDFNode toRDFNode(String value) {
if (isURI(value)) {
return ResourceFactory.createResource(value);
} else if (NumberUtils.isNumber(value)) {
if (value.contains(".")) {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDdouble);
}
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDboolean);
} else {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDinteger);
}
} else {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring);
}
}
示例11: toRDF
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public Model toRDF() {
Model model = ModelFactory.createDefaultModel();
Resource observation = ResourceFactory.createResource();
Resource obsResult = ResourceFactory.createResource();
Resource obsValue = ResourceFactory.createResource();
Resource sensor = ResourceFactory.createResource(
SENSOR_URI_TEMPLATE.replace("${SYSTEM_ID}", systemId).replace("${SENSOR_ID}", sensorId));
model.add(observation, RDF.type, SSN.Observaton)
.add(observation, SSN.observedProperty, property).add(observation, SSN.observedBy, sensor)
.add(observation, SSN.observationResultTime,
ResourceFactory.createTypedLiteral(eventTime.toString(), XSDDatatype.XSDdateTime));
if (featureOfInterest != null) {
model.add(observation, SSN.featureOfInterest, featureOfInterest);
}
model.add(observation, SSN.observationResult, obsResult)
.add(obsResult, RDF.type, SSN.SensorOutput).add(obsResult, SSN.isProducedBy, sensor)
.add(obsResult, SSN.hasValue, obsValue);
model.add(obsValue, RDF.type, QUDT.QuantityValue).add(obsValue, QUDT.quantityValue,
toLiteral(value));
return model;
}
示例12: testToRDF1
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
@Test
public void testToRDF1() {
Observation observation = new Observation("123123", "123123-humidity",
"2016-03-31T16:39:57+01:00",
"http://qudt.org/vocab/quantity#ThermodynamicTemperature",
null, "3.4");
Model model = observation.toRDF();
model.write(System.out, RDFLanguages.strLangTurtle);
assertTrue(model.contains(
null,
SSN.observationResultTime,
ResourceFactory.createTypedLiteral("2016-03-31T16:39:57+01:00",
XSDDatatype.XSDdateTime)));
}
示例13: testToRDF2
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
@Test
public void testToRDF2() {
Observation observation = new Observation("123123", "123123-humidity",
"2016-03-31T16:39:57+01:00",
"http://qudt.org/vocab/quantity#ThermodynamicTemperature",
null, "3.4");
Model model = observation.toRDF();
model.write(System.out, RDFLanguages.strLangTurtle);
assertTrue(model.contains(
null,
SSN.observationResultTime,
ResourceFactory.createTypedLiteral("2016-03-31T16:39:57+01:00",
XSDDatatype.XSDdateTime)));
}
示例14: createTyped
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public static final RDFNode createTyped(String value, Resource valueType)
{
if (value == null) throw new IllegalArgumentException("Param value cannot be null");
// without value type, return default xsd:string value
if (valueType == null) return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring);
// if value type is from XSD namespace, value is treated as typed literal with XSD datatype
if (valueType.getNameSpace().equals(XSD.getURI()))
{
RDFDatatype dataType = NodeFactory.getType(valueType.getURI());
return ResourceFactory.createTypedLiteral(value, dataType);
}
// otherwise, value is treated as URI resource
else
return ResourceFactory.createResource(value);
}
示例15: create
import org.apache.jena.datatypes.xsd.XSDDatatype; //导入依赖的package包/类
public void create(Model model) {
Property id = model
.createProperty("http://www.ontologydesignpatterns.org/ont/eswc/ontology.owl#eswcId");
String sparql = "SELECT ?person " + "WHERE{?person a <" + FOAF.Person
+ ">}";
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution queryExecution = QueryExecutionFactory.create(query,
model);
ResultSet resultSet = queryExecution.execSelect();
for (int i = 1; resultSet.hasNext(); i++) {
QuerySolution solution = resultSet.next();
Resource person = solution.getResource("person");
person.addLiteral(id,
model.createTypedLiteral(i, XSDDatatype.XSDpositiveInteger));
}
}