本文整理汇总了Java中org.apache.jena.rdf.model.StmtIterator类的典型用法代码示例。如果您正苦于以下问题:Java StmtIterator类的具体用法?Java StmtIterator怎么用?Java StmtIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StmtIterator类属于org.apache.jena.rdf.model包,在下文中一共展示了StmtIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLoads
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
@Test
public void testLoads() throws Exception {
// cleanup earlier run. Can't delete dirs on windows after use.
FileUtils.deleteDirectory(new File("tempTDB"));
Model m = ModelLoader.loadModelToMem("Playpen2.ttl");
assertTrue(m != null);
Model mc = ModelLoader.loadModelToMem(m);
assertTrue(mc != null);
Model mtdb = ModelLoader.loadModelToTdb("Playpen2.ttl", "urn:mymodel", "tempTDB");
assertTrue(mtdb != null);
StmtIterator it = mtdb.listStatements();
int nStmts = 0;
while (it.hasNext()) {
System.out.println(it.nextStatement().toString());
nStmts++;
}
// this will fail on windows
FileUtils.deleteDirectory(new File("tempTDB"));
assertTrue(nStmts > 0);
}
示例2: compareModels
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
private boolean compareModels(String resourceName, Model expModel, Model carwledModel) {
StmtIterator iterator = expModel.listStatements();
Statement statement;
boolean modelsAreEqual = true;
while (iterator.hasNext()) {
statement = iterator.next();
if (!carwledModel.contains(statement)) {
LOGGER.error("The crawled model of \"" + resourceName + "\" does not contain the expected statement "
+ statement.toString());
modelsAreEqual = false;
}
}
iterator = carwledModel.listStatements();
while (iterator.hasNext()) {
statement = iterator.next();
if (!expModel.contains(statement)) {
LOGGER.error("The crawled model of \"" + resourceName + "\" contains the unexpected statement "
+ statement.toString());
modelsAreEqual = false;
}
}
return modelsAreEqual;
}
示例3: run
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
@Override
public void run() {
sink.openSinkForUri(uri);
StmtIterator iterator = model.listStatements();
int count = 0;
while (iterator.hasNext()) {
sink.addTriple(uri, iterator.next().asTriple());
try {
Thread.sleep(WAITING_TIME_BETWEEN_TRIPLES);
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
++count;
}
sink.closeSinkForUri(uri);
LOGGER.debug("wrote " + count + " triples for " + uri.getUri().toString());
writingFinishedMutex.release();
}
示例4: filterInboundReferences
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
private Set<URI> filterInboundReferences(final URI uri, final Model model) {
final String withSlash = withSlash(uri).toString();
final String withoutSlash = withoutSlash(uri).toString();
final Set<URI> inboundMembers = new HashSet<>();
final List<Statement> removeList = new ArrayList<>();
for (final StmtIterator inbound = model.listStatements(); inbound.hasNext(); ) {
final Statement s = inbound.next();
final String subject = s.getSubject().toString();
if (!subject.equals(withSlash) && !subject.equals(withoutSlash)) {
removeList.add(s);
logger.trace("Filtering inbound reference: {}", s);
inboundMembers.add(URI.create(subject));
}
}
model.remove(removeList);
return inboundMembers;
}
示例5: filterBinaryReferences
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
/**
* Filter out the binary resource references from the model
* @param uri the URI for the resource
* @param model the RDF Model of the resource
* @return the RDF model with no binary references
* @throws FcrepoOperationFailedException
* @throws IOException
*/
private void filterBinaryReferences(final URI uri, final Model model) throws IOException,
FcrepoOperationFailedException {
final List<Statement> removeList = new ArrayList<>();
for (final StmtIterator it = model.listStatements(); it.hasNext();) {
final Statement s = it.nextStatement();
final RDFNode obj = s.getObject();
if (obj.isResource() && obj.toString().startsWith(repositoryRoot.toString())
&& !s.getPredicate().toString().equals(REPOSITORY_NAMESPACE + "hasTransactionProvider")) {
try (final FcrepoResponse resp = client().head(URI.create(obj.toString())).disableRedirects()
.perform()) {
checkValidResponse(resp, URI.create(obj.toString()), config.getUsername());
final List<URI> linkHeaders = resp.getLinkHeaders("type");
if (linkHeaders.contains(binaryURI)) {
removeList.add(s);
}
}
}
}
model.remove(removeList);
}
示例6: sanitize
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
/**
* Removes statements from the provided model that affect triples that need not be (and indeed
* cannot be) modified directly through PUT, POST or PATCH requests to fedora.
*
* Certain triples included in a resource from fedora cannot be explicitly stored, but because
* they're derived from other content that *can* be stored will still appear identical when the
* other RDF and content is ingested. Examples include those properties that reflect innate
* characteristics of binary resources like file size and message digest, Or triples that
* represent characteristics of rdf resources like the number of children, whether it has
* versions and some of the types.
*
* @param model the RDF statements about an exported resource
* @return the provided model updated to omit statements that may not be updated directly through
* the fedora API
* @throws IOException
* @throws FcrepoOperationFailedException
*/
private Model sanitize(final Model model) throws IOException, FcrepoOperationFailedException {
final List<Statement> remove = new ArrayList<>();
for (final StmtIterator it = model.listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
if ((s.getPredicate().getNameSpace().equals(REPOSITORY_NAMESPACE) && !relaxedPredicate(s.getPredicate()))
|| s.getSubject().getURI().endsWith("fcr:export?format=jcr/xml")
|| s.getSubject().getURI().equals(REPOSITORY_NAMESPACE + "jcr/xml")
|| s.getPredicate().equals(DESCRIBEDBY)
|| s.getPredicate().equals(CONTAINS)
|| s.getPredicate().equals(HAS_MESSAGE_DIGEST)
|| s.getPredicate().equals(HAS_SIZE)
|| (s.getPredicate().equals(RDF_TYPE) && forbiddenType(s.getResource()))) {
remove.add(s);
} else if (s.getObject().isResource()) {
// make sure that referenced repository objects exist
final String obj = s.getResource().toString();
if (obj.startsWith(repositoryRoot.toString())) {
ensureExists(URI.create(obj));
}
}
}
return model.remove(remove);
}
示例7: sortStatementsByHash
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
/**
* Sort statements by hash
*
* @param stmtIterator
* Iterator which is used to get the statements
* @return List of statements sorted by hash
*/
@Deprecated
protected List<Statement> sortStatementsByHash(StmtIterator stmtIterator) {
IntObjectOpenHashMap<Statement> map = new IntObjectOpenHashMap<Statement>();
Statement s;
while (stmtIterator.hasNext()) {
s = stmtIterator.next();
map.put(s.hashCode(), s);
}
int keys[] = new int[map.assigned];
int pos = 0;
for (int i = 0; i < map.allocated.length; ++i) {
if (map.allocated[i]) {
keys[pos] = map.keys[i];
++pos;
}
}
Arrays.sort(keys);
List<Statement> result = new ArrayList<Statement>(keys.length);
for (int i = 0; i < keys.length; ++i) {
result.add(map.get(keys[i]));
}
return result;
}
示例8: DBpediaGenderDictionary
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
public DBpediaGenderDictionary() {
Model model = ModelFactory.createDefaultModel();
Literal maleLit = model.createLiteral(VALUE_MALE, "en");
Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");
RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
while (iter.hasNext()) {
Statement st = iter.next();
Literal lit = st.getObject().asLiteral();
if (lit.equals(maleLit)) {
male.add(st.getSubject().getURI());
} else if (lit.equals(femaleLit)) {
female.add(st.getSubject().getURI());
}
}
}
示例9: addTransitiveObjects
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
private static void addTransitiveObjects(Set<Resource> resources, Set<Resource> reached,
Resource subject, Property predicate) {
resources.add(subject);
reached.add(subject);
StmtIterator it = subject.listProperties(predicate);
try {
while (it.hasNext()) {
RDFNode object = it.next().getObject();
if (object instanceof Resource) {
if (!reached.contains(object)) {
addTransitiveObjects(resources, reached, (Resource)object, predicate);
}
}
}
}
finally {
it.close();
}
}
示例10: addTransitiveSubjects
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
private static void addTransitiveSubjects(Set<Resource> reached, Resource object,
Property predicate, ProgressMonitor monitor) {
if (object != null) {
reached.add(object);
StmtIterator it = object.getModel().listStatements(null, predicate, object);
try {
while (it.hasNext()) {
if (monitor != null && monitor.isCanceled()) {
it.close();
return;
}
Resource subject = it.next().getSubject();
if (!reached.contains(subject)) {
addTransitiveSubjects(reached, subject, predicate, monitor);
}
}
}
finally {
it.close();
}
}
}
示例11: getAllInstances
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
/**
* Gets all instances of a given class and its subclasses.
* @param cls the class to get the instances of
* @return the instances
*/
public static Set<Resource> getAllInstances(Resource cls) {
JenaUtil.setGraphReadOptimization(true);
try {
Model model = cls.getModel();
Set<Resource> classes = getAllSubClasses(cls);
classes.add(cls);
Set<Resource> results = new HashSet<>();
for(Resource subClass : classes) {
StmtIterator it = model.listStatements(null, RDF.type, subClass);
while (it.hasNext()) {
results.add(it.next().getSubject());
}
}
return results;
}
finally {
JenaUtil.setGraphReadOptimization(false);
}
}
示例12: getFirstRange
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
private static Resource getFirstRange(Resource property, Set<Resource> reached) {
Resource directRange = getFirstDirectRange(property);
if(directRange != null) {
return directRange;
}
StmtIterator it = property.listProperties(RDFS.subPropertyOf);
while (it.hasNext()) {
Statement ss = it.next();
if (ss.getObject().isURIResource()) {
Resource superProperty = ss.getResource();
if (!reached.contains(superProperty)) {
reached.add(superProperty);
Resource r = getFirstRange(superProperty, reached);
if (r != null) {
it.close();
return r;
}
}
}
}
return null;
}
示例13: hasIndirectType
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
/**
* Checks whether a given Resource is an instance of a given type, or
* a subclass thereof. Make sure that the expectedType parameter is associated
* with the right Model, because the system will try to walk up the superclasses
* of expectedType. The expectedType may have no Model, in which case
* the method will use the instance's Model.
* @param instance the Resource to test
* @param expectedType the type that instance is expected to have
* @return true if resource has rdf:type expectedType
*/
public static boolean hasIndirectType(Resource instance, Resource expectedType) {
if(expectedType.getModel() == null) {
expectedType = expectedType.inModel(instance.getModel());
}
StmtIterator it = instance.listProperties(RDF.type);
while(it.hasNext()) {
Statement s = it.next();
if(s.getObject().isResource()) {
Resource actualType = s.getResource();
if(actualType.equals(expectedType) || JenaUtil.hasSuperClass(actualType, expectedType)) {
it.close();
return true;
}
}
}
return false;
}
示例14: hasSuperClass
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
private static boolean hasSuperClass(Resource subClass, Resource superClass, Set<Resource> reached) {
StmtIterator it = subClass.listProperties(RDFS.subClassOf);
while(it.hasNext()) {
Statement s = it.next();
if(superClass.equals(s.getObject())) {
it.close();
return true;
}
else if(!reached.contains(s.getResource())) {
reached.add(s.getResource());
if(hasSuperClass(s.getResource(), superClass, reached)) {
it.close();
return true;
}
}
}
return false;
}
示例15: getSPARQL
import org.apache.jena.rdf.model.StmtIterator; //导入依赖的package包/类
@Override
protected String getSPARQL(Constraint constraint) {
SHSPARQLConstraint sc = SHFactory.asSPARQLConstraint(constraint.getParameterValue());
String select = JenaUtil.getStringProperty(sc, SH.select);
if(select == null) {
String message = "Missing " + SH.PREFIX + ":" + SH.select.getLocalName() + " of " + RDFLabels.get().getLabel(sc);
if(sc.isAnon()) {
StmtIterator it = sc.getModel().listStatements(null, null, sc);
if(it.hasNext()) {
Statement s = it.next();
it.close();
message += " at " + RDFLabels.get().getLabel(s.getSubject());
message += " via " + RDFLabels.get().getLabel(s.getPredicate());
}
}
throw new SHACLException(message);
}
return SPARQLSubstitutions.withPrefixes(select, sc);
}