本文整理汇总了Java中org.apache.jena.rdf.model.StmtIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java StmtIterator.next方法的具体用法?Java StmtIterator.next怎么用?Java StmtIterator.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.StmtIterator
的用法示例。
在下文中一共展示了StmtIterator.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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());
}
}
}
示例4: 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;
}
示例5: deleteOutgoingEdges
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public void deleteOutgoingEdges(final Collection<Resource> vertices, final String edgeType) throws IOException {
final Property property = model.getProperty(RdfConstants.BASE_PREFIX + edgeType);
for (final Resource vertex : vertices) {
final Selector selector = new SimpleSelector(vertex, property, (RDFNode) null);
final StmtIterator edges = model.listStatements(selector);
final List<Statement> statementsToRemove = new ArrayList<>();
while (edges.hasNext()) {
final Statement edge = edges.next();
statementsToRemove.add(edge);
}
for (final Statement statement : statementsToRemove) {
model.remove(statement);
}
}
}
示例6: 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;
}
示例7: 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;
}
示例8: activate
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Override
public void activate(final Collection<JenaPosLengthMatch> matches) throws IOException {
final Model model = driver.getModel();
final Property lengthProperty = model.getProperty(BASE_PREFIX + LENGTH);
for (final JenaPosLengthMatch match : matches) {
final Resource segment = match.getSegment();
final int length = match.getLength().getInt();
final int newLength = -length + 1;
final Selector selector = new SimpleSelector(segment, lengthProperty, (RDFNode) null);
final StmtIterator statementsToRemove = model.listStatements(selector);
if (statementsToRemove.hasNext()) {
final Statement oldStatement = statementsToRemove.next();
model.remove(oldStatement);
}
final Statement newStatement = model.createLiteralStatement(segment, lengthProperty, newLength);
model.add(newStatement);
}
}
示例9: 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);
}
示例10: getResourceDefaultType
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public static Resource getResourceDefaultType(Resource resource) {
StmtIterator it = resource.getModel().listStatements(null, null, resource);
try {
while(it.hasNext()) {
Statement s = it.next();
Resource defaultValueType = JenaUtil.getResourceProperty(s.getPredicate(), DASH.defaultValueType);
if(defaultValueType != null) {
return defaultValueType;
}
}
}
finally {
it.close();
}
return null;
}
示例11: getResource
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
protected Resource getResource(Resource resource, String name)
{
if (resource == null) throw new IllegalArgumentException("Resource cannot be null");
StmtIterator it = resource.listProperties();
try
{
while (it.hasNext())
{
Statement stmt = it.next();
if (stmt.getObject().isAnon() && stmt.getPredicate().getLocalName().equals(name))
{
if (log.isTraceEnabled()) log.trace("Found Resource {} for property name: {} ", stmt.getResource(), name);
return stmt.getResource();
}
}
}
finally
{
it.close();
}
return null;
}
示例12: sendData
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
* Will send a {@link org.apache.jena.rdf.model.Model}
*/
public void sendData(Model m) throws Exception {
int sendedSize=0;
//split Model into small parts
StmtIterator sti = m.listStatements();
while(sti.hasNext()){
Model send = ModelFactory.createDefaultModel();
send.setNsPrefixes(m.getNsPrefixMap());
while(sendedSize < maxSize){
Statement stmt = sti.next();
send.add(stmt);
sendedSize+=1;
}
sendDataSnippet(RabbitMQUtils.getData(send));
}
}
示例13: asTriples
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
private Set<Triple> asTriples(Model model) {
Set<Triple> triples = new HashSet<>((int) model.size());
StmtIterator iterator = model.listStatements();
while (iterator.hasNext()) {
Statement statement = iterator.next();
triples.add(statement.asTriple());
}
return triples;
}
示例14: listNotifications
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public List<String> listNotifications(String inboxUrl) throws InterruptedException, IOException{
List<String> notifications=new ArrayList<String>();
UrlRequest urlReq=new UrlRequest(inboxUrl, "Accept", "application/ld+json");
FetchRequest fetched = httpFetcher.fetch(urlReq);
if (fetched.getResponseStatusCode()==200) {
if(fetched.getContent().getType().getMimeType().equals("application/ld+json")) {
Model dcModelRdf = ModelFactory.createDefaultModel();
ByteArrayInputStream bytesIs = new ByteArrayInputStream(fetched.getContent().asBytes());
RDFDataMgr.read(dcModelRdf, bytesIs, inboxUrl, Lang.JSONLD);
try {
bytesIs.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
Resource resource = dcModelRdf.getResource(inboxUrl);
StmtIterator seeAlsoStms = resource.listProperties(RdfReg.LDN_CONTAINS);
while (seeAlsoStms.hasNext()) {
Statement st = seeAlsoStms.next();
// System.out.println(st);
notifications.add(st.getObject().toString());
}
}
}
return notifications;
}
示例15: getValue
import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
* getValue.
*
* @param model Model
* @param resourceProperty String
* @return retval
*/
private static ArrayList<RDFNode> getValue(final Model model, final String resourceProperty) {
final Property property = model.getProperty(resourceProperty);
final ArrayList<RDFNode> retval = new ArrayList<>();
final StmtIterator it =
model.listStatements(new SimpleSelector(null, property, (Resource) null));
while (it.hasNext()) {
final Statement st = it.next();
retval.add(st.getObject());
}
return retval;
}