本文整理汇总了Java中com.hp.hpl.jena.shared.PrefixMapping类的典型用法代码示例。如果您正苦于以下问题:Java PrefixMapping类的具体用法?Java PrefixMapping怎么用?Java PrefixMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrefixMapping类属于com.hp.hpl.jena.shared包,在下文中一共展示了PrefixMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
/**
* Pretty-prints an RDF node and shortens URIs into QNames according to a
* {@link PrefixMapping}.
* @param n An RDF node
* @return An N-Triples style textual representation with URIs shortened to QNames
*/
public static String toString(Node n, PrefixMapping prefixes) {
if (n.isURI()) {
return qNameOrURI(n.getURI(), prefixes);
}
if (n.isBlank()) {
return "_:" + n.getBlankNodeLabel();
}
if (n.isVariable()) {
return "?" + n.getName();
}
if (Node.ANY.equals(n)) {
return "?ANY";
}
// Literal
String s = "\"" + n.getLiteralLexicalForm() + "\"";
if (!"".equals(n.getLiteralLanguage())) {
s += "@" + n.getLiteralLanguage();
}
if (n.getLiteralDatatype() != null) {
s += "^^" + qNameOrURI(n.getLiteralDatatypeURI(), prefixes);
}
return s;
}
示例2: testNodePrettyPrinting
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
@Test
public void testNodePrettyPrinting() {
assertEquals("\"foo\"",
PrettyPrinter.toString(Node.createLiteral("foo")));
assertEquals("\"foo\"@en",
PrettyPrinter.toString(Node.createLiteral("foo", "en", null)));
assertEquals("\"1\"^^xsd:int",
PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint)));
assertEquals("\"1\"^^xsd:int",
PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint), PrefixMapping.Standard));
assertEquals("_:foo",
PrettyPrinter.toString(Node.createAnon(new AnonId("foo"))));
assertEquals("<http://example.org/>",
PrettyPrinter.toString(Node.createURI("http://example.org/")));
assertEquals("<" + RDF.type.getURI() + ">",
PrettyPrinter.toString(RDF.type.asNode(), new PrefixMappingImpl()));
assertEquals("rdf:type",
PrettyPrinter.toString(RDF.type.asNode(), PrefixMapping.Standard));
assertEquals("?x",
PrettyPrinter.toString(Node.createVariable("x")));
assertEquals("?ANY",
PrettyPrinter.toString(Node.ANY));
}
示例3: testNodePrettyPrinting
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public void testNodePrettyPrinting() {
assertEquals("\"foo\"",
PrettyPrinter.toString(Node.createLiteral("foo")));
assertEquals("\"foo\"@en",
PrettyPrinter.toString(Node.createLiteral("foo", "en", null)));
assertEquals("\"1\"^^<" + XSDDatatype.XSDint.getURI() + ">",
PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint)));
assertEquals("\"1\"^^xsd:int",
PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint), PrefixMapping.Standard));
assertEquals("_:foo",
PrettyPrinter.toString(Node.createAnon(new AnonId("foo"))));
assertEquals("<http://example.org/>",
PrettyPrinter.toString(Node.createURI("http://example.org/")));
assertEquals("<" + RDF.type.getURI() + ">",
PrettyPrinter.toString(RDF.type.asNode(), new PrefixMappingImpl()));
assertEquals("rdf:type",
PrettyPrinter.toString(RDF.type.asNode(), PrefixMapping.Standard));
assertEquals("?x",
PrettyPrinter.toString(Node.createVariable("x")));
assertEquals("?ANY",
PrettyPrinter.toString(Node.ANY));
}
示例4: URIPrefixer
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public URIPrefixer(Resource resource, PrefixMapping prefixes) {
this.resource = resource;
String uri = resource.getURI();
Iterator it = prefixes.getNsPrefixMap().entrySet().iterator();
while (it.hasNext()) {
Entry entry = (Entry) it.next();
String entryPrefix = (String) entry.getKey();
String entryURI = (String) entry.getValue();
if (uri.startsWith(entryURI)) {
prefix = entryPrefix;
localName = uri.substring(entryURI.length());
return;
}
}
prefix = null;
localName = null;
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:18,代码来源:URIPrefixer.java
示例5: SparkFilter
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public SparkFilter(OpFilter op, PrefixMapping prefixes) {
this.op = op;
expressions = new HashSet<>();
Iterator<Expr> iterator = op.getExprs().iterator();
while (iterator.hasNext()) {
Expr current = iterator.next();
ExprCompiler translator = new ExprCompiler(prefixes);
expressions.add(translator.translate(current));
}
}
示例6: initTriples
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public static ArrayList<SqlTriple> initTriples(ArrayList<SqlTriple> list, PrefixMapping pMapping, int tabs){
for (int i = 0; i < list.size(); i++){
list.get(i).setTableName(Tags.BGP+getTableId());
list.get(i).setPrefixMapping(pMapping);
list.get(i).setTabs(tabs);
}
return list;
}
示例7: TriplePattern
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public TriplePattern(Triple triple, PrefixMapping prefixes, boolean datasetUsesPrefixes){
// extract and set the subject
if(triple.getSubject().isVariable()) {
subjectType = ElementType.VARIABLE;
subject = triple.getSubject().toString();
}
else {
subjectType = ElementType.CONSTANT;
subject = datasetUsesPrefixes? triple.getSubject().toString(prefixes) :
"<" + triple.getSubject().getURI() + ">";
}
// extract and set the predicate
predicateType = ElementType.CONSTANT;
predicate = triple.getPredicate().toString();
// extract and set the object
if(triple.getObject().isVariable()) {
objectType = ElementType.VARIABLE;
object = triple.getObject().toString(prefixes);
}
else {
objectType = ElementType.CONSTANT;
object = datasetUsesPrefixes ? triple.getObject().toString(prefixes) :
"<" + triple.getObject().getURI() + ">";
}
}
示例8: PtNode
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public PtNode(List<Triple> jenaTriples, PrefixMapping prefixes, Stats stats) {
ArrayList<TriplePattern> triplePatterns = new ArrayList<TriplePattern>();
this.isPropertyTable = true;
this.tripleGroup = triplePatterns;
this.children = new ArrayList<Node>();
this.projection = Collections.emptyList();
this.stats = stats;
for (Triple t : jenaTriples){
triplePatterns.add(new TriplePattern(t, prefixes, this.stats.arePrefixesActive()));
}
this.setIsComplex();
}
示例9: translate
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
@Override
public String translate(String _resultName) {
resultName = _resultName;
String bgp = "-- " + Tags.BGP + "\n";
// empty PrefixMapping when prefixes should be expanded
if (Tags.pMode == PrefixMode.EXPAND) {
prefixes = PrefixMapping.Factory.create();
}
bgp += loadFilterProject();
bgp += joinTriplePatterns();
return bgp;
}
示例10: PigOp2
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
protected PigOp2(PigOp _leftOp, PigOp _rightOp, PrefixMapping _prefixes) {
leftOp = _leftOp;
rightOp = _rightOp;
prefixes = _prefixes;
resultSchema = new ArrayList<String>();
varsWithNulls = new ArrayList<String>();
}
示例11: PrettyTurtleWriter
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
/**
* @param baseIRI Any IRIs starting with this one will be written as relative
*/
public PrettyTurtleWriter(String baseIRI, PrefixMapping prefixes, Writer out) {
this.baseIRI = baseIRI;
this.out = new PrintWriter(out);
this.prefixes = new PrefixMappingImpl();
for (String prefix: prefixes.getNsPrefixMap().keySet()) {
this.prefixes.setNsPrefix(prefix, relativize(prefixes.getNsPrefixURI(prefix)));
}
printPrefixes(this.prefixes);
compactStack.push(false);
}
示例12: printPrefixes
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public void printPrefixes(PrefixMapping prefixes) {
List<String> p = new ArrayList<String>(prefixes.getNsPrefixMap().keySet());
Collections.sort(p);
for (String prefix: p) {
printPrefix(prefix, prefixes.getNsPrefixURI(prefix));
}
}
示例13: qNameOrURI
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
public static String qNameOrURI(String uri, PrefixMapping prefixes) {
if (prefixes == null) {
return "<" + uri + ">";
}
String qName = prefixes.qnameFor(uri);
if (qName != null) {
return qName;
}
return "<" + uri + ">";
}
示例14: testTriplePrettyPrintingWithPrefixMapping
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
@Test
public void testTriplePrettyPrintingWithPrefixMapping() {
PrefixMappingImpl prefixes = new PrefixMappingImpl();
prefixes.setNsPrefixes(PrefixMapping.Standard);
prefixes.setNsPrefix("ex", "http://example.org/");
assertEquals("ex:a rdfs:label \"Example\".",
PrettyPrinter.toString(new Triple(
Node.createURI("http://example.org/a"),
RDFS.label.asNode(),
Node.createLiteral("Example", null, null)), prefixes));
}
示例15: qNameOrURI
import com.hp.hpl.jena.shared.PrefixMapping; //导入依赖的package包/类
private static String qNameOrURI(String uri, PrefixMapping prefixes) {
if (prefixes == null) {
return "<" + uri + ">";
}
String qName = prefixes.qnameFor(uri);
if (qName != null) {
return qName;
}
return "<" + uri + ">";
}