本文整理汇总了Java中org.openrdf.model.impl.LiteralImpl类的典型用法代码示例。如果您正苦于以下问题:Java LiteralImpl类的具体用法?Java LiteralImpl怎么用?Java LiteralImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LiteralImpl类属于org.openrdf.model.impl包,在下文中一共展示了LiteralImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExec3
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Test
public void testExec3() throws Exception {
InMemorySesameEngine eng = InMemorySesameEngine.open();
StatementAddingExecutor sae = new StatementAddingExecutor(
Arrays.asList( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "label" ) ) ), true );
sae.resetStatements( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "tester" ) ) );
Model before = eng.toModel();
eng.execute( sae );
Model after = eng.toModel();
eng.closeDB();
assertTrue( ( before.size() + 1 ) == after.size() );
assertTrue( after.contains( RDFS.DOMAIN, RDFS.LABEL, new LiteralImpl( "tester" ) ) );
assertFalse( after.contains( RDFS.DOMAIN, RDFS.LABEL, new LiteralImpl( "label" ) ) );
}
示例2: setUp
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Repository fromrepo = new SailRepository( new MemoryStore() );
Repository torepo = new SailRepository( new MemoryStore() );
fromrepo.initialize();
torepo.initialize();
from = fromrepo.getConnection();
to = torepo.getConnection();
from.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "test" ) ) );
from.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "test2" ) ) );
from.setNamespace( OWL.PREFIX, OWL.NAMESPACE );
}
示例3: testClear
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Test
public void testClear() throws Exception {
StatementAddingExecutor sae = new StatementAddingExecutor();
sae.addStatement( new StatementImpl( RDFS.DATATYPE, RDFS.LABEL,
new LiteralImpl( "test label" ) ) );
eng.execute( sae );
ListQueryAdapter<URI> q
= OneVarListQueryAdapter.getUriList( "SELECT ?s WHERE { ?s rdfs:label ?o }" );
List<URI> addeduris = new ArrayList<>( eng.queryNoEx( q ) );
q.clear();
EngineUtil2.clear( eng );
List<URI> newuris = eng.queryNoEx( q );
assertNotEquals( addeduris, newuris );
assertTrue( newuris.isEmpty() );
}
示例4: compareData
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
private void compareData( RepositoryConnection testRc, Model expected,
UriBuilder owl, UriBuilder base ) throws Exception {
List<Statement> stmts
= Iterations.asList( testRc.getStatements( null, null, null, false ) );
Model test = new LinkedHashModel( stmts );
assertEquals( "dataset size", expected.size(), test.size() );
compare( "category concept", expected, test, null, RDF.TYPE,
owl.getConceptUri( "Category" ) );
compare( "beverages concept", expected, test,
base.getConceptUri().add( "Category" ).add( "Beverages" ).build(),
null, null );
compare( "dairy products", expected, test,
null, RDFS.LABEL, new LiteralImpl( "Dairy Products" ) );
compare( "chai-beverages link", expected, test,
null, RDFS.LABEL, new LiteralImpl( "Chai Category Beverages" ) );
URI bev
= base.getRelationUri().add( "Category" ).add( "Chai_x_Beverages" ).build();
compare( "chai-beverages category", expected, test,
bev, RDFS.SUBPROPERTYOF, owl.getRelationUri( "Category" ) );
}
示例5: testModifyData
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Test
public void testModifyData() throws Exception {
instance.execute( new ModificationExecutorAdapter( true ) {
@Override
public void exec( RepositoryConnection conn ) throws RepositoryException {
conn.add( new URIImpl( "http://foo.bar/testuri" ), RDFS.LABEL,
new LiteralImpl( "extra" ) );
}
} );
OneVarListQueryAdapter<String> lqa
= OneVarListQueryAdapter.getStringList( "SELECT ?label { ?s rdfs:label ?label }" );
Set<String> names = new HashSet<>( instance.query( lqa ) );
Set<String> expected = new HashSet<>( Arrays.asList( "Reification", "RDR Reification",
"Alan", "First Name", "Purchased", "Reification Model", "Date", "Yugo",
"Cadillac", "Price", "Car", "Database", "Yuri", "OS-EM Semantic Toolkit Reification",
"Has", "Last Name", "W3C Reification", "Human Being", "Data View", "extra" ) );
instance.closeDB();
assertEquals( expected, names );
}
示例6: setUp
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
eng = InMemorySesameEngine.open();
RepositoryConnection rc = eng.getRawConnection();
rc.begin();
rc.add( DATA, null, RDFFormat.NTRIPLES );
rc.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "label" ) ) );
rc.remove( eng.getBaseUri(), MetadataConstants.DCT_MODIFIED, null );
rc.add( eng.getBaseUri(), MetadataConstants.DCT_MODIFIED,
rc.getValueFactory().createLiteral( new Date() ) );
rc.commit();
}
示例7: testGetLabels
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Test
public void testGetLabels() throws Exception {
InMemorySesameEngine eng = InMemorySesameEngine.open();
eng.getRawConnection().begin();
eng.getRawConnection().add( new StatementImpl( RDFS.ISDEFINEDBY,
RDFS.LABEL, new LiteralImpl( "my label" ) ) );
eng.getRawConnection().add( new StatementImpl( RDFS.MEMBER,
RDFS.LABEL, new LiteralImpl( "my label 2" ) ) );
eng.getRawConnection().commit();
String label = Utility.getInstanceLabel( RDFS.ISDEFINEDBY, eng );
assertEquals( "my label", label );
Map<Resource, String> labels = Utility.getInstanceLabels( null, eng );
assertTrue( labels.isEmpty() );
labels = Utility.getInstanceLabels( Arrays.asList(
RDFS.MEMBER, RDFS.DOMAIN ), eng );
assertEquals( "domain", labels.get( RDFS.DOMAIN ) );
assertEquals( "my label 2", labels.get( RDFS.MEMBER ) );
labels = Utility.getInstanceLabels( Arrays.asList( RDFS.ISDEFINEDBY,
RDFS.LITERAL ), null );
assertEquals( 2, labels.size() );
}
示例8: simpleQueryWithoutBindingSet
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Test
public void simpleQueryWithoutBindingSet() throws Exception {
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"),
new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", new LiteralImpl("CoffeeShop"));
bs.addBinding("y", new LiteralImpl("Joe"));
List<BindingSet> bsList = new ArrayList<>();
while (result.hasNext()) {
bsList.add(result.next());
}
System.out.println(bsList);
Assert.assertEquals(1, bsList.size());
Assert.assertEquals(bs, bsList.get(0));
dao.delete(statement, (AccumuloRdfConfiguration) conf);
}
示例9: basicMixUriLiteralBsTest
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Test
public void basicMixUriLiteralBsTest() throws BindingSetConversionException {
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("X",new LiteralImpl("literal1"));
bs.addBinding("Y",new LiteralImpl("5", new URIImpl("http://www.w3.org/2001/XMLSchema#integer")));
bs.addBinding("Z",new LiteralImpl("5.0", new URIImpl("http://www.w3.org/2001/XMLSchema#double")));
bs.addBinding("W",new LiteralImpl("1000", new URIImpl("http://www.w3.org/2001/XMLSchema#long")));
bs.addBinding("A",new URIImpl("http://uri1"));
bs.addBinding("B",new URIImpl("http://uri2"));
bs.addBinding("C",new URIImpl("http://uri3"));
final VariableOrder varOrder = new VariableOrder("A","W","X","Y","Z","B","C");
BindingSetConverter<byte[]> converter = new AccumuloPcjSerializer();
final byte[] byteVal = converter.convert(bs, varOrder);
final BindingSet newBs = converter.convert(byteVal, varOrder);
assertEquals(bs, newBs);
}
示例10: getDefaultValue
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
private Object getDefaultValue(String value, Type type, ObjectConnection con) {
Class<?> ctype = asClass(type);
if (Set.class.equals(ctype)) {
Object v = getDefaultValue(value, getComponentType(ctype, type), con);
if (v == null)
return null;
return Collections.singleton(v);
}
ValueFactory vf = con.getValueFactory();
ObjectFactory of = con.getObjectFactory();
if (of.isDatatype(ctype)) {
URIImpl datatype = new URIImpl("java:" + ctype.getName());
return of.createValue(of.createObject(new LiteralImpl(value, datatype)));
}
return vf.createURI(value);
}
示例11: checkPrimitive
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
/**
* Checks whether the given object is a primitive type and, if so, will
* return a Node that encodes it. Otherwise NULL is returned.
*
* @param o The object to check
* @return a Node or NULL
*/
private Value checkPrimitive( final Object o )
{
if( o instanceof String ) return new LiteralImpl( o.toString() );
if( o instanceof Integer )
return new ValueFactoryImpl().createLiteral( (Integer) o );
if( o instanceof Float )
return new ValueFactoryImpl().createLiteral( (Float) o );
if( o instanceof Double )
return new ValueFactoryImpl().createLiteral( (Double) o );
if( o instanceof URI || o instanceof URL || o instanceof java.net.URI )
return new URIImpl( o.toString() );
return null;
}
示例12: asRdbmsLiteral
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
/****************************************************/
public RdbmsLiteral asRdbmsLiteral(GeneralDBPolyhedron polyhedron) {
try {
URI wkt = new URIImpl(GeoConstants.WKT);
RdbmsLiteral literal =
new RdbmsLiteral(polyhedron.getInternalId(), polyhedron.getVersion(), new LiteralImpl(
polyhedron.stringValue(), wkt));
if (polyhedron instanceof GeneralDBPolyhedron) {
literals.cache(literal);
return (RdbmsLiteral) literal;
}
RdbmsLiteral lit = literals.findInCache(literal);
if (lit == null) {
lit = new RdbmsLiteral(literal);
literals.cache(lit);
}
return lit;
} catch (InterruptedException e) {
throw new RdbmsRuntimeException(e);
}
}
示例13: readObject
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
/**
* Read an instance from the stream. The instance will have been written by the
* {@link #writeObject(java.io.ObjectOutput, Object)} method. Implementations are free
* to create instances of the object read from the stream in any way that they
* feel like. This could be via constructor, factory or reflection.
*
* @param in the object input to read from
* @return the object instance
* @throws java.io.IOException if an I/O error occurs
* @throws ClassNotFoundException if a class could not be found
*/
@Override
public Value readObject(ObjectInput in) throws IOException, ClassNotFoundException {
int type = in.readInt();
String label = DataIO.readString(in);
switch (type) {
case TYPE_URI:
return new URIImpl(label);
case TYPE_BNODE:
return new BNodeImpl(label);
case TYPE_LITERAL:
String lang = DataIO.readString(in);
String dtype = DataIO.readString(in);
if(lang != null) {
return new LiteralImpl(label,lang);
} else if(dtype != null) {
return new LiteralImpl(label, new URIImpl(dtype));
} else {
return new LiteralImpl(label);
}
}
throw new ClassNotFoundException("could not find class with type "+type);
}
示例14: setLabels
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
private void setLabels(URI concept1uri, URI concept2uri, int delay) throws RepositoryException, InterruptedException {
Statement defPrefLabel = new StatementImpl(concept1uri, SKOS.PREF_LABEL, new LiteralImpl("concept"));
Statement updatePrefLabel = new StatementImpl(concept2uri, SKOS.PREF_LABEL, new LiteralImpl("updated concept"));
persistAndNotifyProvider.persistAndNotify(
Helper.createChangeSetModel(defPrefLabel, ChangeTripleService.CHANGETYPE_ADD),
true);
persistAndNotifyProvider.persistAndNotify(
Helper.createChangeSetModel(defPrefLabel, ChangeTripleService.CHANGETYPE_REMOVE),
true);
Thread.sleep(delay);
persistAndNotifyProvider.persistAndNotify(
Helper.createChangeSetModel(updatePrefLabel, ChangeTripleService.CHANGETYPE_ADD),
true);
}
示例15: enrichIncompleteIndex
import org.openrdf.model.impl.LiteralImpl; //导入依赖的package包/类
@Override
public void enrichIncompleteIndex(NanopubCreator npCreator) {
if (title != null) {
npCreator.addPubinfoStatement(DC.TITLE, new LiteralImpl(title));
}
for (String creator : creators) {
if (creator.indexOf("://") > 0) {
npCreator.addCreator(new URIImpl(creator));
} else if (creator.matches("[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]")) {
npCreator.addCreator(creator);
} else {
throw new IllegalArgumentException("Author has to be URI or ORCID: " + creator);
}
}
for (URI seeAlsoUri : seeAlsoUris) {
npCreator.addPubinfoStatement(RDFS.SEEALSO, seeAlsoUri);
}
}