Skip to content

Commit

Permalink
inject application name
Browse files Browse the repository at this point in the history
  • Loading branch information
heinpa committed Aug 9, 2020
1 parent e11874c commit 5c9094a
Show file tree
Hide file tree
Showing 27 changed files with 215 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " oa:hasSource <" + myQanaryQuestion.getUri() + ">; " //
+ " ] ; " //
+ " oa:hasBody <" + urls + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) {
+ " oa:hasSource <" + uriQuestion + ">; " //
+ " ] . " //
+ " ?a oa:hasBody <" + urls + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " + "WHERE { "//
+ "BIND (IRI(str(RAND())) AS ?a) ." //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws SparqlQueryFa
+ " ?a a qa:AnnotationOfRelation . " + " ?a oa:hasTarget [ " + " a oa:SpecificResource; " //
+ " oa:hasSource <" + uriQuestion + ">; " + " ] . " //
+ " ?a oa:hasBody <" + urls + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:annotatedAt ?time "
+ "}} " //
+ "WHERE { " //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " oa:hasSource <" + myQanaryQuestion.getUri() + ">; " //
+ " ] ; " //
+ " oa:hasBody <" + urls + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " ] " //
+ " ] . " //
+ " ?a oa:hasBody <" + l.link + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " + "}} " //
+ "WHERE { " //
+ " BIND (IRI(str(RAND())) AS ?a) ."//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " ] " //
+ " ] . " //
+ " ?a oa:hasBody <" + l.link + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " + "}} " //
+ "WHERE { " //
+ " BIND (IRI(str(RAND())) AS ?a) ."//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " ] " //
+ " ] . " //
+ " ?a oa:hasBody <" + s.link + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " + "}} " //
+ "WHERE { " //
+ " BIND (IRI(str(RAND())) AS ?a) ."//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " ] " //
+ " ] . " //
+ " ?a oa:hasBody <" + l.link + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " + "}} " //
+ "WHERE { " //
+ " BIND (IRI(str(RAND())) AS ?a) ."//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " ] " //
+ " ] . " //
+ " ?a oa:hasBody <" + l.link + "> ;" //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " + "}} " //
+ "WHERE { " //
+ " BIND (IRI(str(RAND())) AS ?a) ."//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger " //
+ " ] " //
+ " ] ; " //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger " //
+ " ] " //
+ " ] ; " //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.wdaqua.qanary.dbpediaSpotlight;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -20,8 +21,8 @@ public class Application {
* QanaryServiceController in the qanary_component-template
*/
@Bean
public QanaryComponent qanaryComponent() {
return new DBpediaSpotlightNER();
public QanaryComponent qanaryComponent(@Value("${spring.application.name}") final String applicationName) {
return new DBpediaSpotlightNER(applicationName);
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.jena.vocabulary.DB;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand All @@ -33,6 +35,11 @@
public class DBpediaSpotlightNER extends QanaryComponent {
private static final Logger logger = LoggerFactory.getLogger(DBpediaSpotlightNER.class);

private final String applicationName;

public DBpediaSpotlightNER(@Value("${spring.application.name}") final String applicationName) {
this.applicationName = applicationName;
}
/**
* default processor of a QanaryMessage
*/
Expand Down Expand Up @@ -135,7 +142,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) {
// STEP3: Pass the information to the component and execute it
// logger.info("apply commons alignment on outgraph");

DBpediaSpotlightNER qaw = new DBpediaSpotlightNER();
DBpediaSpotlightNER qaw = new DBpediaSpotlightNER(applicationName);

List<String> stEn = new ArrayList<String>();
stEn = qaw.getResults(myQuestion);
Expand All @@ -152,27 +159,27 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) {
//STEP4: Push the result of the component to the triplestore

for (Selection s : selections) {
String sparql = "prefix qa: <http://www.wdaqua.eu/qa#> "
+ "prefix oa: <http://www.w3.org/ns/openannotation/core/> "
+ "prefix xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "INSERT { "
+ "GRAPH <" + myQanaryQuestion.getOutGraph() + "> { "
+ " ?a a qa:AnnotationOfSpotInstance . "
+ " ?a oa:hasTarget [ "
+ " a oa:SpecificResource; "
+ " oa:hasSource <" + myQanaryQuestion.getUri() + ">; "
+ " oa:hasSelector [ "
+ " a oa:TextPositionSelector ; "
+ " oa:start \"" + s.begin + "\"^^xsd:nonNegativeInteger ; "
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger "
+ " ] "
+ " ] ; "
+ " oa:annotatedBy <http://spotlight.sztaki.hu:2222/rest/spot> ; "
+ " oa:AnnotatedAt ?time "
+ "}} "
+ "WHERE { "
+ "BIND (IRI(str(RAND())) AS ?a) ."
+ "BIND (now() as ?time) "
String sparql = "prefix qa: <http://www.wdaqua.eu/qa#> " //
+ "prefix oa: <http://www.w3.org/ns/openannotation/core/> " //
+ "prefix xsd: <http://www.w3.org/2001/XMLSchema#> " //
+ "INSERT { " //
+ "GRAPH <" + myQanaryQuestion.getOutGraph() + "> { " //
+ " ?a a qa:AnnotationOfSpotInstance . " //
+ " ?a oa:hasTarget [ " //
+ " a oa:SpecificResource; " //
+ " oa:hasSource <" + myQanaryQuestion.getUri() + ">; " //
+ " oa:hasSelector [ " //
+ " a oa:TextPositionSelector ; " //
+ " oa:start \"" + s.begin + "\"^^xsd:nonNegativeInteger ; " //
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger " //
+ " ] " //
+ " ] ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " // <http://spotlight.sztaki.hu:2222/rest/spot>
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
+ "BIND (IRI(str(RAND())) AS ?a) ." //
+ "BIND (now() as ?time) " //
+ "}";
myQanaryUtils.updateTripleStore(sparql, myQanaryQuestion.getEndpoint().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger " //
+ " ] " //
+ " ] ; " //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger " //
+ " ] " //
+ " ] ; " //
+ " oa:annotatedBy "+this.applicationName+" ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.wdaqua.qanary.FOX;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -20,8 +21,8 @@ public class Application {
* QanaryServiceController in the qanary_component-template
*/
@Bean
public QanaryComponent qanaryComponent() {
return new FOXComponent();
public QanaryComponent qanaryComponent(@Value("${spring.application.name}") final String applicationName) {
return new FOXComponent(applicationName);
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand All @@ -32,6 +33,12 @@ public class FOXComponent extends QanaryComponent {
private static final Logger logger = LoggerFactory.getLogger(FOXComponent.class);
private static final String foxService = "http://fox-demo.aksw.org/api";

private final String applicationName;

public FOXComponent(@Value("${spring.application.name}") final String applicationName) {
this.applicationName = applicationName;
}

/**
* default processor of a QanaryMessage
*/
Expand Down Expand Up @@ -83,34 +90,34 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
myQanaryUtils.updateTripleStore(sparql, myQanaryMessage.getEndpoint().toString());

//Align to QANARY commons
sparql = "prefix qa: <http://www.wdaqua.eu/qa#> "
+ "prefix oa: <http://www.w3.org/ns/openannotation/core/> "
+ "prefix xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "INSERT { "
+ "GRAPH <" + myQanaryMessage.getOutGraph() + "> { "
+ " ?a a qa:AnnotationOfSpotInstance . "
+ " ?a oa:hasTarget [ "
+ " a oa:SpecificResource; "
+ " oa:hasSource <" + myQanaryQuestion.getUri() + ">; "
+ " oa:hasSelector [ "
+ " a oa:TextPositionSelector ; "
+ " oa:start ?begin ; "
+ " oa:end ?end "
+ " ] "
+ " ] ; "
+ " oa:annotatedBy <http://fox-demo.aksw.org> ; "
+ " oa:AnnotatedAt ?time "
+ "}} "
+ "WHERE { "
+ " SELECT ?a ?s ?begin ?end ?time "
+ " WHERE { "
+ " graph <" + namedGraphTemp + "> { "
+ " ?s <http://ns.aksw.org/scms/beginIndex> ?begin . "
+ " ?s <http://ns.aksw.org/scms/endIndex> ?end . "
+ " BIND (IRI(str(RAND())) AS ?a) ."
+ " BIND (now() as ?time) "
+ " } "
+ " } "
sparql = "prefix qa: <http://www.wdaqua.eu/qa#> " //
+ "prefix oa: <http://www.w3.org/ns/openannotation/core/> " //
+ "prefix xsd: <http://www.w3.org/2001/XMLSchema#> " //
+ "INSERT { " //
+ "GRAPH <" + myQanaryMessage.getOutGraph() + "> { " //
+ " ?a a qa:AnnotationOfSpotInstance . " //
+ " ?a oa:hasTarget [ " //
+ " a oa:SpecificResource; " //
+ " oa:hasSource <" + myQanaryQuestion.getUri() + ">; " //
+ " oa:hasSelector [ " //
+ " a oa:TextPositionSelector ; " //
+ " oa:start ?begin ; " //
+ " oa:end ?end " //
+ " ] " //
+ " ] ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ;" // <http://fox-demo.aksw.org>
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
+ " SELECT ?a ?s ?begin ?end ?time " //
+ " WHERE { " //
+ " graph <" + namedGraphTemp + "> { " //
+ " ?s <http://ns.aksw.org/scms/beginIndex> ?begin . " //
+ " ?s <http://ns.aksw.org/scms/endIndex> ?end . " //
+ " BIND (IRI(str(RAND())) AS ?a) ." //
+ " BIND (now() as ?time) " //
+ " } " //
+ " } " //
+ "}";
myQanaryUtils.updateTripleStore(sparql, myQanaryMessage.getEndpoint().toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,28 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
logger.info("apply vocabulary alignment on outgraph");
// TODO: implement this (custom for every component)
for (Selection s : selections) {
String sparql = "prefix qa: <http://www.wdaqua.eu/qa#> "
+ "prefix oa: <http://www.w3.org/ns/openannotation/core/> "
+ "prefix xsd: <http://www.w3.org/2001/XMLSchema#> " + "INSERT { " + "GRAPH <" + myQanaryMessage.getOutGraph() + "> { "
+ " ?a a qa:AnnotationOfSpotInstance . " + " ?a oa:hasTarget [ "
+ " a oa:SpecificResource; " + " oa:hasSource <" + myQanaryQuestion.getUri() + ">; "
+ " oa:hasSelector [ " + " a oa:TextPositionSelector ; "
+ " oa:start \"" + s.begin + "\"^^xsd:nonNegativeInteger ; "
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger " + " ] "
+ " ] ; " + " oa:annotatedBy "+this.applicationName+" ; "
+ " oa:AnnotatedAt ?time " + "}} " + "WHERE { " + "BIND (IRI(str(RAND())) AS ?a) ."
+ "BIND (now() as ?time) " + "}";
String sparql = "prefix qa: <http://www.wdaqua.eu/qa#> " //
+ "prefix oa: <http://www.w3.org/ns/openannotation/core/> " //
+ "prefix xsd: <http://www.w3.org/2001/XMLSchema#> " //
+ "INSERT { " //
+ "GRAPH <" + myQanaryMessage.getOutGraph() + "> { " //
+ " ?a a qa:AnnotationOfSpotInstance . " //
+ " ?a oa:hasTarget [ " //
+ " a oa:SpecificResource; " //
+ " oa:hasSource <" + myQanaryQuestion.getUri() + ">; " //
+ " oa:hasSelector [ " //
+ " a oa:TextPositionSelector ; " //
+ " oa:start \"" + s.begin + "\"^^xsd:nonNegativeInteger ; " //
+ " oa:end \"" + s.end + "\"^^xsd:nonNegativeInteger " //
+ " ] " //
+ " ] ; " //
+ " oa:annotatedBy <urn:qanary:"+this.applicationName+"> ; " //
+ " oa:AnnotatedAt ?time " //
+ "}} " //
+ "WHERE { " //
+ "BIND (IRI(str(RAND())) AS ?a) ." //
+ "BIND (now() as ?time) " //
+ "}";
myQanaryUtils.updateTripleStore(sparql, myQanaryMessage.getEndpoint().toString());
}
return myQanaryMessage;
Expand Down
Loading

0 comments on commit 5c9094a

Please sign in to comment.