org.apache.jena.rdf.model.Model.createLiteral()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中org.apache.jena.rdf.model.Model.createLiteral()方法的一些代码示例,展示了Model.createLiteral()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Model.createLiteral()方法的具体详情如下:
包路径:org.apache.jena.rdf.model.Model
类名称:Model
方法名:createLiteral

Model.createLiteral介绍

[英]Create an untyped literal from a String value with a specified language.
[中]使用指定语言从字符串值创建非类型化文字。

代码示例

代码示例来源:origin: apache/jena

/**
 * <p>Remove the statement that the given string is a label for
 * this resource.  If this statement
 * is not true of the current model, nothing happens.</p>
 * @param label A label string to be removed
 * @param lang A lang tag
 */
@Override
public void removeLabel( String label, String lang ) {
  removeLabel( getModel().createLiteral( label, lang ) );
}

代码示例来源:origin: apache/jena

/**
 * <p>Answer true if this resource has the given comment.</p>
 * @param comment The comment to test for
 * @param lang The optional language tag, or null for don't care.
 * @return True if this resource has <code>comment</code> as a comment.
 */
@Override
public boolean hasComment( String comment, String lang ) {
  return hasComment( getModel().createLiteral( comment, lang ) );
}

代码示例来源:origin: apache/jena

/**
 * <p>Add the given label to this resource.</p>
 * @param label A label string for this resource
 * @param lang The language attribute for this label (EN, FR, etc) or null if not specified.
 * @exception ProfileException If the {@link Profile#LABEL()} property is not supported in the current language profile.
 */
@Override
public void addLabel( String label, String lang ) {
  addLabel( getModel().createLiteral( label, lang ) );
}

代码示例来源:origin: apache/jena

/**
 * <p>Remove the statement that the given string is a comment on
 * this resource.  If this statement
 * is not true of the current model, nothing happens.</p>
 * @param comment A comment string to be removed
 * @param lang A lang tag
 */
@Override
public void removeComment( String comment, String lang ) {
  removeComment( getModel().createLiteral( comment, lang ) );
}

代码示例来源:origin: org.apache.jena/jena-core

public void testRDFNodeAsLiteral()
{
  final Model m = ModelHelper.modelWithStatements(this, "");
  final Literal l = m.createLiteral("hello, world");
  Assert.assertSame(l, ((RDFNode) l).asLiteral());
}

代码示例来源:origin: apache/jena

/**
 * <p>Add the given version information to this resource.</p>
 * @param info A version information string for this resource
 * @exception ProfileException If the {@link Profile#VERSION_INFO()} property is not supported in the current language profile.
 */
@Override
public void addVersionInfo( String info ) {
  checkProfile( getProfile().VERSION_INFO(), "VERSION_INFO" );
  addProperty( getProfile().VERSION_INFO(), getModel().createLiteral( info ) );
}

代码示例来源:origin: apache/jena

public void testRDFNodeAsLiteral()
{
  final Model m = ModelHelper.modelWithStatements(this, "");
  final Literal l = m.createLiteral("hello, world");
  Assert.assertSame(l, ((RDFNode) l).asLiteral());
}

代码示例来源:origin: org.apache.jena/jena-core

public void testLiteralHasModel()
{
  testLiteralHasModel(model, model.createLiteral("hello, world"));
  testLiteralHasModel(model, model.createLiteral("hello, world", "en-UK"));
  testLiteralHasModel(model, model.createLiteral("hello, world", true));
  testLiteralHasModel(model, model.createTypedLiteral("hello, world"));
  testLiteralHasModel(model, model.createTypedLiteral(false));
  testLiteralHasModel(model, model.createTypedLiteral(17));
  testLiteralHasModel(model, model.createTypedLiteral('x'));
}

代码示例来源:origin: apache/jena

public void testAddLiteralPassesLiteralUnmodified()
{
  final Resource r = model.createResource();
  final Literal lit = model.createLiteral("spoo");
  r.addLiteral(RDF.value, lit);
  Assert.assertTrue("model should contain unmodified literal",
      model.contains(null, RDF.value, lit));
}

代码示例来源:origin: apache/jena

public void testAddWithLiteralObject()
{
  final Literal lit = model.createLiteral("spoo");
  model.addLiteral(X, P, lit);
  Assert.assertTrue(model.contains(X, P, lit));
  Assert.assertTrue(model.containsLiteral(X, P, lit));
}

代码示例来源:origin: apache/jena

public void testInModel()
{
  final Model m1 = createModel();
  final Model m2 = createModel();
  final Literal l1 = m1.createLiteral("17");
  final Literal l2 = l1.inModel(m2);
  Assert.assertEquals(l1, l2);
  Assert.assertSame(m2, l2.getModel());
}

代码示例来源:origin: org.apache.jena/jena-core

public void testInModel()
{
  final Model m1 = createModel();
  final Model m2 = createModel();
  final Literal l1 = m1.createLiteral("17");
  final Literal l2 = l1.inModel(m2);
  Assert.assertEquals(l1, l2);
  Assert.assertSame(m2, l2.getModel());
}

代码示例来源:origin: apache/jena

@Override
public void setUp()
{
  model = createModel();
  final Resource S2 = model.createResource(TestReifiedStatements.anchor
      + "subject2");
  S = model.createResource(TestReifiedStatements.anchor + "subject");
  P = model.createProperty(TestReifiedStatements.anchor + "predicate");
  O = model.createLiteral(TestReifiedStatements.anchor + "object");
  SPO = model.createStatement(S, P, O);
  SPO2 = model.createStatement(S2, P, O);
}

代码示例来源:origin: apache/jena

protected void testPlainString( final Model model, final String tv )
{
  final Literal l = model.createLiteral(tv);
  Assert.assertEquals(tv, l.getString());
  Assert.assertEquals(tv, l.getLexicalForm());
  Assert.assertEquals("", l.getLanguage());
}

代码示例来源:origin: apache/jena

protected void testLanguagedString( final Model model, final String tv,
    final String lang )
{
  final Literal l = model.createLiteral(tv, lang);
  Assert.assertEquals(tv, l.getString());
  Assert.assertEquals(tv, l.getLexicalForm());
  Assert.assertEquals(lang, l.getLanguage());
}

代码示例来源:origin: apache/jena

@Test public void testInitialBindings3()
{
  try(QueryExecution qExec = makeQExec("SELECT * {?s ?p 'x1'}")) {
    QuerySolutionMap init = new QuerySolutionMap() ;
    init.add("z", m.createLiteral("zzz"));
    qExec.setInitialBinding(init) ;
    ResultSet rs = qExec.execSelect() ;
    QuerySolution qs = rs.nextSolution() ;
    assertTrue("Initial setting not set correctly now", qs.getLiteral("z").getLexicalForm().equals("zzz")) ;
  }
}

代码示例来源:origin: apache/jena

@Test public void testInitialBindings1()
{
  QueryExecution qExec = makeQExec("SELECT * {?s ?p ?o}") ;
  QuerySolutionMap init = new QuerySolutionMap() ;
  init.add("o", m.createLiteral("y1"));
  qExec.setInitialBinding(init) ;
  int count = queryAndCount(qExec) ;
  assertEquals("Initial binding didn't restrict query properly", 1, count) ;
}

代码示例来源:origin: apache/jena

public void testXMLLiteral() {
  Literal ll;
  
  ll = m.createLiteral("<bad",true);
  
  assertTrue("Error checking must be off.",((EnhNode)ll).asNode().getLiteralIsXML());
  ll = m.createTypedLiteral("<bad/>",XMLLiteralType.theXMLLiteralType);
  assertFalse("Error checking must be on.",((EnhNode)ll).asNode().getLiteralIsXML());
  ll = m.createTypedLiteral("<good></good>",XMLLiteralType.theXMLLiteralType);
  assertTrue("Well-formed XMLLiteral.",((EnhNode)ll).asNode().getLiteralIsXML());

}

代码示例来源:origin: apache/jena

@Test public void testInitialBindingsConstruct1()
{
  try(QueryExecution qExec = makeQExec("CONSTRUCT {?s ?p ?z} {?s ?p 'x1'}")) {
    QuerySolutionMap init = new QuerySolutionMap() ;
    init.add("z", m.createLiteral("zzz"));
    
    qExec.setInitialBinding(init) ;
    Model r = qExec.execConstruct() ;
  
    assertTrue("Empty model", r.size() > 0 ) ;
  
    Property p1 = m.createProperty(ns+"p1") ;
  
    assertTrue("Empty model", r.contains(null,p1, init.get("z"))) ; 
  }
}

代码示例来源:origin: apache/jena

@Test public void testInitialBindingsConstruct2()
{
  try(QueryExecution qExec = makeQExec("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }")) {
    QuerySolutionMap init = new QuerySolutionMap() ;
    init.add("o", m.createLiteral("x1"));
    
    qExec.setInitialBinding(init) ;
    Model r = qExec.execConstruct() ;
  
    assertTrue("Empty model", r.size() > 0 ) ;
  
    Property p1 = m.createProperty(ns+"p1") ;
  
    assertTrue("Empty model", r.contains(null, p1, init.get("x1"))) ; 
  }
}

相关文章

Model类方法