Skip to content
Snippets Groups Projects
Commit bddf5bf2 authored by Andreas Schärtl's avatar Andreas Schärtl
Browse files

app: show more meta information in node info

Show ulo:name, ulo:paratype (e.g. lemma) and ulo:sourceref.  I would
like to now reference the sourceref to the original source as that is
a real world application.
parent 1d894ec8
Branches
No related tags found
No related merge requests found
package info.mathhub.uloapi.html;
import info.mathhub.uloapi.config.Config;
import info.mathhub.uloapi.query.Meta;
import info.mathhub.uloapi.query.Query;
import info.mathhub.uloapi.query.Statistics;
import info.mathhub.uloapi.query.Timer;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Statement;
import org.slf4j.Logger;
......@@ -82,10 +82,12 @@ public class Routes {
final String base64uri = request.params("base64uri");
final String uri = Base64.decode(base64uri);
final Meta meta = query.getMeta(uri);
final List<PrintableIRI> uses = PrintableIRI.convert(query.getUses(uri));
final Map<String, Object> model = new HashMap<>();
model.put("uri", uri);
model.put("meta", meta);
model.put("uses", uses);
return new ModelAndView(withGlobals(model), "explore_node.flt");
......
package info.mathhub.uloapi.query;
import info.mathhub.uloapi.ontology.ULO;
import org.eclipse.rdf4j.model.IRI;
/**
* Contains meta information for a given URI.
*/
public class Meta {
/**
* IRI of the object.
*/
public IRI iri;
/**
* {@link ULO#name} of the object.
*/
public String name;
/**
* {@link ULO#sourceref} of the object.
*/
public String sourceref;
/**
* {@link ULO#paratype} of this object.
*/
public String paratype;
public String getName() {
return this.name;
}
public String getSourceref() {
return this.sourceref;
}
public String getParatype() {
return this.paratype;
}
@Override
public String toString() {
return String.format(
"Meta(iri=%s name=%s sourceref=%s paratype=%s)",
this.iri.toString(), this.name, this.sourceref, this.paratype
);
}
}
......@@ -197,4 +197,49 @@ public class Query {
return GraphDB.execute(this.serverUrl, this.repository, operation);
}
/**
* Try to create a {@link Meta} object for argument {@code nodeuri}.
*
* @param nodeuri The URI of the node for which we query the meta data.
* @return A {@link Meta} object for argument {@code nodeuri}. Never {@code null},
* but the returned object can contain {@code null} fields.
*/
public Meta getMeta(String nodeuri) {
final GraphDB.Operation<Meta> operation = (manager, repository, connection) -> {
final IRI iri = IRIs.fromString(nodeuri);
final Meta meta = new Meta();
meta.iri = iri;
meta.name = this.getSingleValueOrNull(iri, ULO.name);
meta.sourceref = this.getSingleValueOrNull(iri, ULO.sourceref);
meta.paratype = this.getSingleValueOrNull(iri, ULO.paratype);
return meta;
};
return GraphDB.execute(this.serverUrl, this.repository, operation);
}
/**
* Given subject and predicate, return the first matching object.
*
* @return The object as returned by the database, converted to a {@link String}.
* If no element was found, this method returns {@code null}.
*/
private String getSingleValueOrNull(IRI subject, IRI predicate) {
final GraphDB.Operation<String> operation = (manager, repository, connection) -> {
final RepositoryResult<Statement> result = connection.getStatements(subject, predicate, null);
if (!result.hasNext()) {
return null;
}
final Value object = result.next().getObject();
return object.stringValue();
};
return GraphDB.execute(this.serverUrl, this.repository, operation);
}
}
......@@ -19,6 +19,30 @@
</li>
</ul>
<h3>Name</h3>
<ul>
<li>
<code>${meta.name}</code>
</li>
</ul>
<h3>Paragraph Type (<code>ulo:paratype</code>)</h3>
<ul>
<li>
<code>${meta.paratype}</code>
</li>
</ul>
<h3>Source Reference (<code>ulo:sourceref</code>)</h3>
<ul>
<li>
<code>${meta.sourceref}</code>
</li>
</ul>
<h3>Node uses...</h3>
<ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment