本文整理匯總了Java中com.hp.hpl.jena.rdf.model.StmtIterator.nextStatement方法的典型用法代碼示例。如果您正苦於以下問題:Java StmtIterator.nextStatement方法的具體用法?Java StmtIterator.nextStatement怎麽用?Java StmtIterator.nextStatement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.rdf.model.StmtIterator
的用法示例。
在下文中一共展示了StmtIterator.nextStatement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUndefinedResources
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
public Collection<Resource> getUndefinedResources(Model model) {
Set<Resource> result = new HashSet<Resource>();
StmtIterator it = model.listStatements();
while (it.hasNext()) {
Statement stmt = it.nextStatement();
if (stmt.getSubject().isURIResource()
&& stmt.getSubject().getURI().startsWith(namespace)
&& !resources.contains(stmt.getSubject())) {
result.add(stmt.getSubject());
}
if (stmt.getPredicate().equals(RDF.type)) continue;
if (stmt.getObject().isURIResource()
&& stmt.getResource().getURI().startsWith(namespace)
&& !resources.contains(stmt.getResource())) {
result.add(stmt.getResource());
}
}
return result;
}
示例2: runQueryOnInstance
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
/**
* Runs a given Jena Query on a given instance and adds the inferred triples
* to a given Model.
* @param queryWrapper the wrapper of the CONSTRUCT query to execute
* @param queryModel the query Model
* @param newTriples the Model to write the triples to
* @param instance the instance to run the inferences on
* @param checkContains true to only call add if a Triple wasn't there yet
* @return true if changes were done (only meaningful if checkContains == true)
*/
public static boolean runQueryOnInstance(QueryWrapper queryWrapper, Model queryModel, Model newTriples, Resource instance, boolean checkContains) {
boolean changed = false;
QueryExecution qexec = ARQFactory.get().createQueryExecution(queryWrapper.getQuery(), queryModel);
QuerySolutionMap bindings = new QuerySolutionMap();
bindings.add(SPIN.THIS_VAR_NAME, instance);
Map<String,RDFNode> initialBindings = queryWrapper.getTemplateBinding();
if(initialBindings != null) {
for(String varName : initialBindings.keySet()) {
RDFNode value = initialBindings.get(varName);
bindings.add(varName, value);
}
}
qexec.setInitialBinding(bindings);
Model cm = qexec.execConstruct();
StmtIterator cit = cm.listStatements();
while(cit.hasNext()) {
Statement s = cit.nextStatement();
if(!checkContains || !queryModel.contains(s)) {
changed = true;
newTriples.add(s);
}
}
return changed;
}
示例3: getNumberOfLinks
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
private Integer getNumberOfLinks(String nif) {
Model model = ModelFactory.createDefaultModel();
model.read(new ByteArrayInputStream(nif.getBytes()), null, "TTL");
StmtIterator iter = model.listStatements();
Integer result = 0;
while (iter.hasNext()) {
Statement stm = iter.nextStatement();
if (NIF21Format.RDF_PROPERTY_IDENTREF.equals(stm.getPredicate().toString())) {
result += 1;
}
}
return result;
}
示例4: getAllEntityEvents
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
static ArrayList<String> getAllEntityEvents (Dataset dataset, String entity) {
ArrayList<String> events = new ArrayList<String>();
Iterator<String> it = dataset.listNames();
while (it.hasNext()) {
String name = it.next();
if (!name.equals(instanceGraph) && (!name.equals(provenanceGraph))) {
Model namedModel = dataset.getNamedModel(name);
StmtIterator siter = namedModel.listStatements();
while (siter.hasNext()) {
Statement s = siter.nextStatement();
String object = getObjectValue(s).toLowerCase();
if (object.indexOf(entity.toLowerCase()) > -1) {
String subject = s.getSubject().getURI();
if (!events.contains(subject)) {
events.add(subject);
}
}
}
}
}
return events;
}
示例5: getAllNoteDescriptors
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
public ResourceDescriptor[] getAllNoteDescriptors(String outlineUri) {
Model outlineModel;
try {
outlineModel = MindRaider.outlineCustodian.getModel(outlineUri);
Property property = RDF.type;
String literal = MindRaiderConstants.MR_OWL_CLASS_CONCEPT;
StmtIterator i = outlineModel.listStatements((com.hp.hpl.jena.rdf.model.Resource)null,property,outlineModel.getResource(literal));
ArrayList<String> noteUris=new ArrayList<String>();
while(i.hasNext()) {
Statement s=i.nextStatement();
noteUris.add(s.getSubject().getURI());
}
return getDescriptorsForNoteUris(true, outlineModel, noteUris.toArray(new String[noteUris.size()]));
} catch (Exception e) {
logger.debug("Unable to get resource descriptors",e); // {{debug}}
}
return null;
}
示例6: createStatement
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
/**
* Create a statement.
*
* @param subject
* the resource
* @param predicateUri
* the predicate url
* @param objectUri
* the object url
* @param literal
* the literal flag
* @return a Statement object
*/
public Statement createStatement(Resource subject, String predicateUri,
String objectUri, boolean literal) {
RDFNode objectResource;
Property predicateResource = model.createProperty(predicateUri);
if (literal) {
objectResource = model.createLiteral(objectUri);
} else {
objectResource = model.createResource(objectUri);
}
subject.addProperty(predicateResource, objectResource);
StmtIterator i = model.listStatements(subject, predicateResource,
objectResource);
if (i.hasNext()) {
return i.nextStatement();
}
JOptionPane.showMessageDialog(MindRaider.mainJFrame,
"Unable to fetch statement.", "Error",
JOptionPane.ERROR_MESSAGE);
return null;
}
示例7: getPropertyValues
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
<T> List<T> getPropertyValues(final Resource resource, final String property, final Function<Statement,Optional<T>> filter) {
Preconditions.checkState(this.model!=null);
final StmtIterator stmts = resource.listProperties(this.model.createProperty(property));
try {
final List<T> values=Lists.newArrayList();
while(stmts.hasNext()) {
final Statement st=stmts.nextStatement();
final Optional<T> result = filter.apply(st);
if(result.isPresent()) {
values.add(result.get());
}
}
return values;
} finally {
stmts.close();
}
}
示例8: parseN3
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
private static void parseN3(GrabMappingsHandler handler, String infileurl) {
Model model = ModelFactory.createDefaultModel();
model.read(infileurl, "N3");
AResourceImpl sub = new AResourceImpl();
AResourceImpl pred = new AResourceImpl();
AResourceImpl objres = new AResourceImpl();
ALiteralImpl objlit = new ALiteralImpl();
StmtIterator it = model.listStatements();
while (it.hasNext()) {
Statement stmt = it.nextStatement();
RDFNode object = stmt.getObject();
sub.setResource(stmt.getSubject());
pred.setResource(stmt.getPredicate());
if (object instanceof Literal) {
objlit.setLiteral((Literal) object);
handler.statement(sub, pred, objlit);
} else {
objres.setResource((Resource) object);
handler.statement(sub, pred, objres);
}
}
}
示例9: getRequest
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
private List getRequest(Resource pcho)
{
List l = new ArrayList();
StmtIterator iter = pcho.listProperties();
while ( iter.hasNext() )
{
Statement stmt = iter.nextStatement();
RDFNode node = stmt.getObject();
String uri = stmt.getPredicate().getURI();
if ( node.isResource() || !_fields.containsKey(uri) ) { continue; }
String prop = getQName(stmt.getPredicate());
String value = node.asLiteral().getString();
String[] vocs = _fields.get(uri);
for ( String key : normalizeInternal(value) )
{
Map m = new HashMap(3);
m.put("originalField", prop + ";" + value);
m.put("value", key);
m.put("vocabularies", vocs);
l.add(m);
}
}
return l;
}
示例10: mergeResources
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
public static void mergeResources(Resource src, Resource trg)
{
Property sameAs = src.getModel().getProperty(URI_SAMEAS);
StmtIterator iter = src.listProperties();
while ( iter.hasNext() )
{
Statement stmt = iter.nextStatement();
Property p = stmt.getPredicate();
if ( p.equals(sameAs) ) { continue; }
trg.addProperty(p, stmt.getObject());
iter.remove();
}
}
示例11: getDefaultCortexSupport
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
/**
* Retrieve the dhus system supported items for file scanning processing.
* Is considered supported all classes having
* <code>http://www.gael.fr/dhus#metadataExtractor</code> property
* connection.
* @return the list of supported class names.
*/
public static synchronized String[] getDefaultCortexSupport ()
{
DrbCortexModel model;
try
{
model = DrbCortexModel.getDefaultModel ();
}
catch (IOException e)
{
throw new UnsupportedOperationException (
"Drb cortex not properly initialized.");
}
ExtendedIterator it=model.getCortexModel ().getOntModel ().listClasses ();
List<String>list = new ArrayList<String> ();
while (it.hasNext ())
{
OntClass cl = (OntClass)it.next ();
OntProperty metadata_extractor_p = cl.getOntModel().getOntProperty(
"http://www.gael.fr/dhus#support");
StmtIterator properties = cl.listProperties (metadata_extractor_p);
while (properties.hasNext ())
{
Statement stmt = properties.nextStatement ();
LOGGER.debug ("Scanner Support Added for " +
stmt.getSubject ().toString ());
list.add (stmt.getSubject ().toString ());
}
}
return list.toArray (new String[list.size ()]);
}
示例12: bulkUpdate
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
/**
* Method called to Chunk the triples into N-Sized batches and post to VIVO.
* This is designed to work around / handle errors when posting sets of triples
* over 10,000 to the API.
*
* @param namedGraph String with named graph.
* @param changeModel Jena model with set of changes to sync to store.
* @param changeType Either add or remove.
* @return Boolean true if update was successful.
* @throws IOException
*/
private Boolean bulkUpdate(String namedGraph, Model changeModel, String changeType) throws IOException {
// Temporary model to hold
Model tmpModel = ModelFactory.createDefaultModel();
Integer bSize = Integer.parseInt(batchSize);
// Use an integer to count triples rather than calling size on the model
// during each loop.
Integer size = 0;
StmtIterator iter = changeModel.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
tmpModel.add(stmt);
size++;
if (size >= bSize) {
// Submit
log.info("Submitting " + size + " triples to " + namedGraph);
submitBatch(tmpModel, namedGraph, changeType);
// Reset the tmp model.
tmpModel.removeAll();
// Reset the counter.
size = 0;
}
}
log.info("model size:" + tmpModel.size());
// Submit the remaining statements, if any.
if (tmpModel.size() > 0) {
submitBatch(tmpModel, namedGraph, changeType);
}
return true;
}
示例13: getUndefinedClasses
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
public Collection<Resource> getUndefinedClasses(Model model) {
Set<Resource> result = new HashSet<Resource>();
StmtIterator it = model.listStatements(null, RDF.type, (RDFNode) null);
while (it.hasNext()) {
Statement stmt = it.nextStatement();
if (stmt.getObject().isURIResource()
&& stmt.getResource().getURI().startsWith(namespace)
&& !classes.contains(stmt.getObject())) {
result.add(stmt.getResource());
}
}
return result;
}
示例14: getUndefinedProperties
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
public Collection<Property> getUndefinedProperties(Model model) {
Set<Property> result = new HashSet<Property>();
StmtIterator it = model.listStatements();
while (it.hasNext()) {
Statement stmt = it.nextStatement();
if (stmt.getPredicate().getURI().startsWith(namespace)
&& !properties.contains(stmt.getPredicate())) {
result.add(stmt.getPredicate());
}
}
return result;
}
示例15: usesVocabulary
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入方法依賴的package包/類
public boolean usesVocabulary(Model model) {
StmtIterator it = model.listStatements();
while (it.hasNext()) {
Statement stmt = it.nextStatement();
if (stmt.getPredicate().getURI().startsWith(namespace)) {
return true;
}
if (stmt.getPredicate().equals(RDF.type) && stmt.getResource().getURI().startsWith(namespace)) {
return true;
}
}
return false;
}