Java Code Examples for org.apache.jena.rdf.model.Statement#getObject()
The following examples show how to use
org.apache.jena.rdf.model.Statement#getObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReasoningOntology.java From Heracles with GNU General Public License v3.0 | 6 votes |
public HashMap<String, String> lexToURI(){ StmtIterator iter = ontology.listStatements(new SimpleSelector(null, ontology.getProperty(NS+"#lex"),(Literal)null)); HashMap<String, String> ontoConcepts=new HashMap<String,String>(); while (iter.hasNext()) { Statement stmt = iter.nextStatement(); Resource subject = stmt.getSubject(); // get the subject RDFNode lex = stmt.getObject(); StmtIterator iter2 = ontology.listStatements(new SimpleSelector( subject, ontology.getProperty("http://www.w3.org/2000/01/rdf-schema#subClassOf"), ontology.getResource(this.URI_Mention))); if (iter2.hasNext()){ ontoConcepts.put(lex.toString(), subject.getURI()); } else { System.out.println("No subclass of Mention: "+subject.toString()); } // } return ontoConcepts; }
Example 2
Source File: Exporter.java From fcrepo-import-export with Apache License 2.0 | 6 votes |
/** * 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); }
Example 3
Source File: RDFIntroSpector.java From ontopia with Apache License 2.0 | 6 votes |
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); } } }
Example 4
Source File: LexicalMatcherAlphaImpl.java From FCA-Map with GNU General Public License v3.0 | 5 votes |
private static Set<String> acquireAllLiteralsLexicalFormsWith(Resource resource, Property property) { Set<String> s = new HashSet<>(); for (StmtIterator it = resource.listProperties(property); it.hasNext(); ) { Statement stmt = it.nextStatement(); RDFNode object = stmt.getObject(); if (!object.isLiteral()) continue; String lb = object.asLiteral().getString(); if (lb != null && !lb.isEmpty() && !lb.trim().equals("")) { s.add(lb); } } return s; }
Example 5
Source File: LexicalMatcherImpl.java From FCA-Map with GNU General Public License v3.0 | 5 votes |
private <T extends Resource> Set<String> getAllLiteralString(T r, Property property) { Set<String> literalStrings = new HashSet<>(); for (StmtIterator it = r.listProperties(property); it.hasNext(); ) { Statement stmt = it.nextStatement(); RDFNode obj = stmt.getObject(); if (!obj.isLiteral()) continue; String ls = obj.asLiteral().getLexicalForm(); if (null != ls && !ls.isEmpty()) { literalStrings.add(ls); } } return literalStrings; }
Example 6
Source File: ReasoningOntology.java From Heracles with GNU General Public License v3.0 | 5 votes |
public HashSet<String> getObjects(String subjectURI, String predicateURI){ StmtIterator iter = ontology.listStatements(new SimpleSelector(ontology.getResource(subjectURI), ontology.getProperty(predicateURI),(RDFNode)null)); HashSet<String> targetTypes = new HashSet<String>(); while (iter.hasNext()) { Statement stmt = iter.nextStatement(); // get next statement RDFNode object = stmt.getObject(); // get the object if (object.isResource()){ targetTypes.add(object.asResource().getURI()); } else if (object.isLiteral()){ targetTypes.add(object.asLiteral().getLexicalForm()); } } targetTypes.remove(null); return targetTypes; }
Example 7
Source File: JenaUtil.java From shacl with Apache License 2.0 | 5 votes |
public static RDFNode getProperty(Resource subject, Property predicate) { Statement s = subject.getProperty(predicate); if(s != null) { return s.getObject(); } else { return null; } }
Example 8
Source File: TemplateImpl.java From Processor with Apache License 2.0 | 5 votes |
protected Map<Property, Parameter> addSuperParameters(Template template, Map<Property, Parameter> params) { if (template == null) throw new IllegalArgumentException("Template Set cannot be null"); if (params == null) throw new IllegalArgumentException("Parameter Map cannot be null"); StmtIterator it = template.listProperties(LDT.extends_); try { while (it.hasNext()) { Statement stmt = it.next(); if (!stmt.getObject().isResource() || !stmt.getObject().asResource().canAs(Template.class)) { if (log.isErrorEnabled()) log.error("Template's '{}' ldt:extends value '{}' is not an LDT Template", getURI(), stmt.getObject()); throw new OntologyException("Template's '" + getURI() + "' ldt:extends value '" + stmt.getObject() + "' is not an LDT Template"); } Template superTemplate = stmt.getObject().as(Template.class); Map<Property, Parameter> superArgs = superTemplate.getLocalParameters(); Iterator<Entry<Property, Parameter>> entryIt = superArgs.entrySet().iterator(); while (entryIt.hasNext()) { Entry<Property, Parameter> entry = entryIt.next(); params.putIfAbsent(entry.getKey(), entry.getValue()); // reject Parameters for existing predicates } addSuperParameters(superTemplate, params); // recursion to super class } } finally { it.close(); } return params; }
Example 9
Source File: TemplateImpl.java From Processor with Apache License 2.0 | 5 votes |
@Override public final boolean hasSuperTemplate(Template superTemplate) { if (superTemplate == null) throw new IllegalArgumentException("Template cannot be null"); StmtIterator it = listProperties(LDT.extends_); try { while (it.hasNext()) { Statement stmt = it.next(); if (!stmt.getObject().isResource() || !stmt.getObject().asResource().canAs(Template.class)) { if (log.isErrorEnabled()) log.error("Template's '{}' ldt:extends value '{}' is not an LDT Template", getURI(), stmt.getObject()); throw new OntologyException("Template's '" + getURI() + "' ldt:extends value '" + stmt.getObject() + "' is not an LDT Template"); } Template nextTemplate = stmt.getObject().as(Template.class); if (nextTemplate.equals(superTemplate) || nextTemplate.hasSuperTemplate(superTemplate)) return true; } } finally { it.close(); } return false; }
Example 10
Source File: RDFToTopicMapConverter.java From ontopia with Apache License 2.0 | 5 votes |
private void doConversion(Model model) throws JenaException { StatementHandler totm = new ToTMStatementHandler(); AResourceWrapper subjw = new AResourceWrapper(); AResourceWrapper propw = new AResourceWrapper(); AResourceWrapper objtw = new AResourceWrapper(); ALiteralWrapper litlw = new ALiteralWrapper(); ResIterator it = model.listSubjects(); while (it.hasNext()) { Resource subject = (Resource) it.next(); StmtIterator it2 = subject.listProperties(); // get all statements while (it2.hasNext()) { Statement stmt = (Statement) it2.next(); subjw.resource = stmt.getSubject(); propw.resource = stmt.getPredicate(); RDFNode obj = stmt.getObject(); if (obj instanceof Resource) { objtw.resource = (Resource) obj; totm.statement(subjw, propw, objtw); } else { litlw.literal = (Literal) obj; totm.statement(subjw, propw, litlw); } } } }
Example 11
Source File: ShaclLiteTestCaseResultReader.java From RDFUnit with Apache License 2.0 | 5 votes |
@Override public ShaclLiteTestCaseResult read(final Resource resource) { checkNotNull(resource); TestCaseResult test = TestCaseResultReader.create(SHACL.message, SHACL.severity).read(resource); RDFNode focusNode = null; for (Statement smt : resource.listProperties(SHACL.focusNode).toList()) { focusNode = smt.getObject(); } checkNotNull(focusNode); return new ShaclLiteTestCaseResultImpl(resource, test.getTestCaseUri(), test.getSeverity(), test.getMessage(), test.getTimestamp(), focusNode); }
Example 12
Source File: SHRuleImpl.java From shacl with Apache License 2.0 | 4 votes |
@Override public RDFNode getSubject() { Statement s = getProperty(SH.subject); return s != null ? s.getObject() : null; }
Example 13
Source File: SHRuleImpl.java From shacl with Apache License 2.0 | 4 votes |
@Override public RDFNode getObject() { Statement s = getProperty(SH.object); return s != null ? s.getObject() : null; }
Example 14
Source File: HtmlTriplePatternFragmentWriterImpl.java From Server.Java with MIT License | 4 votes |
/** * * @param outputStream * @param datasource * @param fragment * @param tpfRequest * @throws IOException * @throws TemplateException */ @Override public void writeFragment(ServletOutputStream outputStream, IDataSource datasource, ITriplePatternFragment fragment, ITriplePatternFragmentRequest tpfRequest) throws IOException, TemplateException{ Map data = new HashMap(); // base.ftl.html data.put("assetsPath", "assets/"); data.put("header", datasource.getTitle()); data.put("date", new Date()); // fragment.ftl.html data.put("datasourceUrl", tpfRequest.getDatasetURL()); data.put("datasource", datasource); // Parse controls to template variables StmtIterator controls = fragment.getControls(); while (controls.hasNext()) { Statement control = controls.next(); String predicate = control.getPredicate().getURI(); RDFNode object = control.getObject(); if (!object.isAnon()) { String value = object.isURIResource() ? object.asResource().getURI() : object.asLiteral().getLexicalForm(); data.put(predicate.replaceFirst(HYDRA, ""), value); } } // Add metadata data.put("totalEstimate", fragment.getTotalSize()); data.put("itemsPerPage", fragment.getMaxPageSize()); // Add triples and datasources List<Statement> triples = fragment.getTriples().toList(); data.put("triples", triples); data.put("datasources", getDatasources()); // Calculate start and end triple number Long start = ((tpfRequest.getPageNumber() - 1) * fragment.getMaxPageSize()) + 1; data.put("start", start); data.put("end", start + (triples.size() < fragment.getMaxPageSize() ? triples.size() : fragment.getMaxPageSize())); // Compose query object Map query = new HashMap(); query.put("subject", !tpfRequest.getSubject().isVariable() ? tpfRequest.getSubject().asConstantTerm() : ""); query.put("predicate", !tpfRequest.getPredicate().isVariable() ? tpfRequest.getPredicate().asConstantTerm() : ""); query.put("object", !tpfRequest.getObject().isVariable() ? tpfRequest.getObject().asConstantTerm() : ""); data.put("query", query); // Get the template (uses cache internally) Template temp = datasource instanceof IndexDataSource ? indexTemplate : datasourceTemplate; // Merge data-model with template temp.process(data, new OutputStreamWriter(outputStream)); }