Skip to content

Commit

Permalink
Lsq queries now use the newer hashing method
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed Nov 1, 2023
1 parent ed0fce7 commit 7a4d573
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
CWD = $(shell pwd)

POM = -f pom.xml
# Maven Clean Install Skip ; skip tests, javadoc, scaladoc, etc
MS = mvn -DskipTests -Dmaven.javadoc.skip=true -Dskip
MCIS = $(MS) clean install
MCCS = $(MS) clean compile

VER = $(error specify VER=releasefile-name e.g. VER=1.9.7-rc2)
loud = echo "@@" $(1);$(1)

# Source: https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile
.PHONY: help

.ONESHELL:
help: ## Show these help instructions
@sed -rn 's/^([a-zA-Z_-]+):.*?## (.*)$$/"\1" "\2"/p' < $(MAKEFILE_LIST) | xargs printf "make %-20s# %s\n"

distjar: ## Create only the standalone jar-with-dependencies of rpt
$(MCCS) $(POM) package -Pstandalone,dist -pl :lsq-pkg-uberjar-cli -am $(ARGS)
file=`find '$(CWD)/lsq-pkg-parent/lsq-pkg-uberjar-cli/target' -name '*-jar-with-dependencies.jar'`
printf '\nCreated package:\n\n%s\n\n' "$$file"

rpm-rebuild: ## Rebuild the rpm package (minimal build of only required modules)
$(MCIS) $(POM) -Prpm -am -pl :lsq-pkg-rpm-cli $(ARGS)

rpm-reinstall: ## Reinstall rpm (requires prior build)
@p1=`find lsq-pkg-parent/lsq-pkg-rpm-cli/target | grep '\.rpm$$'`
sudo rpm -U "$$p1"

rpm-rere: rpm-rebuild rpm-reinstall ## Rebuild and reinstall rpm package


deb-rebuild: ## Rebuild the deb package (minimal build of only required modules)
$(MCIS) $(POM) -Pdeb -am -pl :lsq-pkg-deb-cli $(ARGS)

deb-reinstall: ## Reinstall deb (requires prior build)
@p1=`find lsq-pkg-parent/lsq-pkg-deb-cli/target | grep '\.deb$$'`
sudo dpkg -i "$$p1"

deb-rere: deb-rebuild deb-reinstall ## Rebuild and reinstall deb package


docker: ## Build Docker image
$(MCIS) $(POM) -am -pl :lsq-pkg-docker-cli $(ARGS)
cd lsq-pkg-parent/lsq-pkg-docker-cli && $(MS) jib:dockerBuild && cd ../..

release-bundle: ## Create files for Github upload
@set -eu
ver=$(VER)
$(call loud,$(MAKE) deb-rebuild)
p1=`find lsq-pkg-parent/lsq-pkg-deb-cli/target | grep '\.deb$$'`
$(call loud,cp "$$p1" "rpt-$${ver/-/\~}.deb")
$(call loud,$(MAKE) rpm-rebuild)
p1=`find lsq-pkg-parent/lsq-pkg-rpm-cli/target | grep '\.rpm$$'`
$(call loud,cp "$$p1" "rpt-$$ver.rpm")
$(call loud,$(MAKE) distjar)
file=`find '$(CWD)/lsq-pkg-parent/lsq-pkg-uberjar-cli/target' -name '*-jar-with-dependencies.jar'`
$(call loud,cp "$$file" "rpt-$$ver.jar")
$(call loud,$(MAKE) docker)
$(call loud,docker tag aksw/rpt aksw/rpt:$$ver)
$(call loud,gh release create v$$ver "rpt-$${ver/-/\~}.deb" "rpt-$$ver.rpm" "rpt-$$ver.jar")
$(call loud,docker push aksw/rpt:$$ver)
$(call loud,docker push aksw/rpt)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TestLsqModel {
public void test01() {
Model model = ModelFactory.createDefaultModel();
// Query query = QueryFactory.create("SELECT ?o ?p ?s { ?s ?p ?o }");
Query query = QueryFactory.create("SELECT ?s ?p ?o { ?s ?p ?o } OFFSET 5 LIMIT 10");
Query query = QueryFactory.create("SELECT ?p ?o { ?s ?p ?o } OFFSET 5 LIMIT 10");
LsqQuery before = model.createResource().as(LsqQuery.class);
QueryHash hash = QueryHash.createHash(query);
System.out.println(hash);
Expand Down
33 changes: 30 additions & 3 deletions lsq-model/src/main/java/org/aksw/simba/lsq/model/LsqQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.aksw.commons.util.string.StringUtils;
import org.aksw.jenax.annotation.reprogen.HashId;
import org.aksw.jenax.annotation.reprogen.Iri;
import org.aksw.jenax.annotation.reprogen.ResourceView;
import org.aksw.jenax.annotation.reprogen.StringId;
import org.aksw.jenax.arq.util.syntax.QueryHash;
import org.aksw.jenax.reprogen.hashid.HashIdCxt;
import org.aksw.simba.lsq.vocab.LSQ;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.Syntax;
import org.apache.jena.rdf.model.Resource;

import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing;
import com.google.common.io.BaseEncoding;
import org.apache.jena.query.Query;
import org.apache.jena.rdf.model.Resource;


/**
Expand Down Expand Up @@ -83,6 +90,15 @@ public interface LsqQuery
@Iri(LSQ.Terms.hasRemoteExec)
Set<RemoteExecution> getRemoteExecutions();

@StringId
default String getStringId(HashIdCxt cxt) {
String prefix = StringUtils.toLowerCamelCase(LsqQuery.class.getSimpleName());
String hash = getHash();
if (hash == null) {
hash = cxt.getHashAsString(this);
}
return prefix + "-" + hash.replace('/', '-');
}

/**
* Index of remote executions by the experiment config resource
Expand All @@ -105,7 +121,7 @@ default Map<Resource, LocalExecution> getLocalExecutionMap() {
//}


public static String createHash(String str) {
public static String createHashOld(String str) {
// System.out.println("Hashing " + str.replace('\n', ' '));

// FIXME The hash computation of the jsa-mapper includes the properties and use the RDF term serialization - so the hashes do not align
Expand All @@ -120,6 +136,17 @@ public static String createHash(String str) {
return result;
}

public static String createHash(String str) {
String result;
try {
Query query = QueryFactory.create(str, Syntax.syntaxARQ);
result = QueryHash.createHash(query).toString();
} catch (Exception e) {
result = createHashOld(str);
}
return result;
}

default LsqQuery setQueryAndHash(String str) {
String hash = createHash(str);

Expand Down

0 comments on commit 7a4d573

Please sign in to comment.