diff --git a/src/ulo-storage-endpoint/src/main/java/info/mathhub/uloapi/cli/Main.java b/src/ulo-storage-endpoint/src/main/java/info/mathhub/uloapi/cli/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..e15345a2db28b1df6d3a0141d94af07386b27c6a --- /dev/null +++ b/src/ulo-storage-endpoint/src/main/java/info/mathhub/uloapi/cli/Main.java @@ -0,0 +1,58 @@ +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()); + } + } +} diff --git a/src/ulo-storage-endpoint/src/main/java/info/mathhub/uloapi/query/GraphDB.java b/src/ulo-storage-endpoint/src/main/java/info/mathhub/uloapi/query/GraphDB.java index 3ce11cad9deccf007add93c64a5ea9b5ff60d6be..7dad53a8ecb830bf70f6f29eb3e5a7a94956b469 100644 --- a/src/ulo-storage-endpoint/src/main/java/info/mathhub/uloapi/query/GraphDB.java +++ b/src/ulo-storage-endpoint/src/main/java/info/mathhub/uloapi/query/GraphDB.java @@ -1,5 +1,6 @@ package info.mathhub.uloapi.query; +import info.mathhub.uloapi.config.Config; import org.eclipse.rdf4j.repository.Repository; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; @@ -48,6 +49,23 @@ public class GraphDB { 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. * diff --git a/src/ulo-storage-endpoint/src/main/resources/uloapi.properties b/src/ulo-storage-endpoint/src/main/resources/uloapi.properties index ee82139db6ca7f3e43ec82a1f0da0121399fdd08..a7b5c951f4c44f08fa3e491681d2d143a75450f4 100644 --- a/src/ulo-storage-endpoint/src/main/resources/uloapi.properties +++ b/src/ulo-storage-endpoint/src/main/resources/uloapi.properties @@ -1,2 +1,2 @@ info.mathhub.uloapi.config.serverurl=http://rdf:7200 -info.mathhub.uloapi.config.repository=myulo \ No newline at end of file +info.mathhub.uloapi.config.repository=fckw \ No newline at end of file