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

ulo-storage-endpoint: add some counting functionality

parent 17d92769
Branches
No related tags found
No related merge requests found
package info.mathhub.uloapi.cli;
import info.mathhub.uloapi.query.GraphDB;
import info.mathhub.uloapi.query.ULO;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.repository.RepositoryResult;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class Main {
public static void main(String[] args) {
final List<IRI> predicates = Arrays.asList(
ULO.action_times, ULO.aligned_with, ULO.alternative_for, ULO.antonym,
ULO.automatically_proved, ULO.axiom, ULO.check_time, ULO.constructs,
ULO.contains, ULO.counter_example_for, ULO.crossrefs, ULO.declaration,
ULO.defines, ULO.definition, ULO.deprecated, ULO.derived, ULO.docref,
ULO.example, ULO.example_for, ULO.experimental, ULO.external_size,
ULO.file, ULO.folder, ULO.formalizes, ULO.function, ULO.generated_by,
ULO.hypernym, ULO.hyponym, ULO.implementation_uses,
ULO.implementation_uses_implementation_of,
ULO.implementation_uses_interface_of, ULO.important, ULO.inductive_on,
ULO.inspired_by, ULO.instance_of, ULO.inter_statement,
ULO.interface_uses, ULO.interface_uses_implementation_of,
ULO.interface_uses_interface_of, ULO.internal_size, ULO.justifies,
ULO.last_checked_at, ULO.library, ULO.library_group, ULO.logical,
ULO.mutual_block, ULO.name, ULO.nyms, ULO.organizational, ULO.para,
ULO.paratype, ULO.phrase, ULO.physical, ULO.predicate, ULO.primitive,
ULO.proof, ULO.proposition, ULO.revision, ULO.rule, ULO.same_as,
ULO.section, ULO.see_also, ULO.similar_to, ULO.size_properties,
ULO.sourceref, ULO.specified_in, ULO.specifies, ULO.statement,
ULO.superseded_by, ULO.theorem, ULO.theory, ULO.type, ULO.typedec,
ULO.unimportant, ULO.universe, ULO.uses, ULO.uses_implementation,
ULO.uses_interface
);
for (final IRI predicate : predicates) {
final GraphDB.Operation<Long> operation = (manager, repository, connection) -> {
final RepositoryResult<Statement> result = connection.getStatements(null, predicate, null);
final Iterator<Statement> iterator = result.iterator();
long count = 0;
while (iterator.hasNext()) {
count += 1;
result.next();
}
return count;
};
final long count = GraphDB.execute(operation);
System.out.printf("%s - %s\n", count, predicate.toString());
}
}
}
package info.mathhub.uloapi.query; package info.mathhub.uloapi.query;
import info.mathhub.uloapi.config.Config;
import org.eclipse.rdf4j.repository.Repository; import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.repository.RepositoryException;
...@@ -48,6 +49,23 @@ public class GraphDB { ...@@ -48,6 +49,23 @@ public class GraphDB {
void apply() throws Exception; void apply() throws Exception;
} }
/**
* Run an operation on a remote repository. Uses default credentials as defines in the
* {@code uloapi.properties} file.
*
* @param op The operation to execute.
* @param <T> The return type of the operation
* @return The return value of the operation, i.e. of argument {@code op}.
* @throws OperationException If the logic of the operation itself causes some kind of error.
* @throws RepositoryException If communication with the remote database fails.
*/
public static <T> T execute(Operation<T> op) {
final String serverUrl = Config.serverUrl();
final String repositoryName = Config.repository();
return GraphDB.execute(serverUrl, repositoryName, op);
}
/** /**
* Run an operation on a remote repository. * Run an operation on a remote repository.
* *
......
info.mathhub.uloapi.config.serverurl=http://rdf:7200 info.mathhub.uloapi.config.serverurl=http://rdf:7200
info.mathhub.uloapi.config.repository=myulo info.mathhub.uloapi.config.repository=fckw
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment