Skip to content

Commit

Permalink
Merge master into implement-kgqan-component
Browse files Browse the repository at this point in the history
  • Loading branch information
heinpa committed Jul 31, 2024
2 parents 07bc8ba + 34f50b7 commit 601c13d
Show file tree
Hide file tree
Showing 32 changed files with 287 additions and 63 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Qanary component test pipeline

on:
pull_request:
branches: [master]

jobs:
test-java:
runs-on: ubuntu-latest
env:
BABELFY_API_KEY : someapikey
CHATGPT_API_KEY : someapikey
DANDELION_API_KEY : someapikey
MEANINGCLOUD_API_KEY : someapikey
TAGME_API_KEY : someapikey
TEXTRAZOR_API_KEY : someapikey
OPENAI_API_KEY : someapikey
BABELFY_API_LIVE_TEST_ACTIVE : false
PLATYPUS_API_LIVE_TEST_ACTIVE : false
TEXTRAZOR_API_LIVE_TEST_ACTIVE : false
CHATGPT_API_LIVE_TEST_ACTIVE : false
DANDELION_API_LIVE_TEST_ACTIVE : false
MEANINGCLOUD_API_LIVE_TEST_ACTIVE : false
AGDISTIS_API_LIVE_TEST_ACTIVE : false
OPENAI_API_LIVE_TEST_ACTIVE : false
TAGME_API_LIVE_TEST_ACTIVE : false
steps:
- name: Configure java
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
- uses: actions/checkout@v4
- name: Test Java components
run: bash -c ./service_config/test_java_components.sh
test-python:
runs-on: ubuntu-latest
steps:
- name: Configure Python
uses: actions/setup-python@v5
id: setup_python
with:
python-version: '3.12'
- uses: actions/checkout@v4
- name: Cache virtual environments
uses: actions/cache@v4
with:
key: environments-${{ runner.os }}-${{ steps.setup_python.outputs.python-version}}-${{ hashFiles('**/requirements.txt') }}
path: environments
- name: Test Python components
run: bash -c ./service_config/test_python_components.sh
2 changes: 1 addition & 1 deletion qanary-component-MT-Python-HelsinkiNLP/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
log_cli = 1
log_cli = 0
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
log_cli_date_format=%Y-%m-%d %H:%M:%S
Expand Down
2 changes: 1 addition & 1 deletion qanary-component-MT-Python-LibreTranslate/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
log_cli = 1
log_cli = 0
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
log_cli_date_format=%Y-%m-%d %H:%M:%S
Expand Down
2 changes: 1 addition & 1 deletion qanary-component-MT-Python-MBart/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
log_cli = 1
log_cli = 0
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
log_cli_date_format=%Y-%m-%d %H:%M:%S
Expand Down
4 changes: 2 additions & 2 deletions qanary-component-MT-Python-MBart/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ langid==1.1.6
mock==3.0.5
python-dotenv==0.21.1
qanary_helpers==0.2.2
transformers==4.25.1
transformers==4.41.0
sentencepiece==0.1.97
torch==1.13.1
torch==2.3.0
gunicorn==20.1.0
protobuf==3.20.*
pytest
Expand Down
2 changes: 1 addition & 1 deletion qanary-component-MT-Python-NLLB/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
log_cli = 1
log_cli = 0
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
log_cli_date_format=%Y-%m-%d %H:%M:%S
Expand Down
4 changes: 2 additions & 2 deletions qanary-component-MT-Python-NLLB/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ langdetect==1.0.9
mock==3.0.5
python-dotenv==0.21.1
qanary_helpers==0.2.2
transformers==4.25.1
transformers==4.41.0
sentencepiece==0.1.97
torch==1.13.1
torch==2.3.0
gunicorn==20.1.0
protobuf==3.20.*
pytest
Expand Down
2 changes: 1 addition & 1 deletion qanary-component-NED-DBpediaSpotlight/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-NED-DBpediaSpotlight</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>

<parent>
<groupId>eu.wdaqua.qanary</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@ public class Application {

private static final Logger logger = LoggerFactory.getLogger(Application.class);


/**
* default main
* defalt main
*
* @param args
*/
public static void main(String[] args) {
applicationContext = SpringApplication.run(Application.class, args);
}

/**
* get configuration of configuration
*
* @param myDBpediaSpotlightServiceFetcher
* @param testQuestion
* @param confidenceMinimum
* @param endpoint
* @param performLiveCheckOnComponentStart
* @param ignore
* @return
* @throws DBpediaSpotlightServiceNotAvailable
*/
@Bean
public DBpediaSpotlightConfiguration myDBpediaSpotlightConfiguration( //
@Autowired DBpediaSpotlightServiceFetcher myDBpediaSpotlightServiceFetcher, //
Expand Down Expand Up @@ -80,6 +95,11 @@ private void checkSpotlightServiceAvailability(String testQuestion, String endpo
}
}

/**
* specific configuration of OpenAPI documentation
*
* @return
*/
@Bean
public OpenAPI customOpenAPI() {
String appVersion = getClass().getPackage().getImplementationVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,13 @@ public DBpediaSpotlightServiceFetcher(
this.minimumConfidence = minimumConfidence;
}


/**
* fetch data from the configured DBpedia Spotlight endpoint
*
*
* @param myQuestion
* @param endpoint
* @param minimumConfidence
* @return
* @throws Exception
* @throws ClientProtocolException
* @throws IOException
*/
public JsonArray getJsonFromService(String myQuestion) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public class FoundDBpediaResource {
public int support;
public double similarityScore;

/**
* constructor
*
* @param surfaceForm
* @param offset
* @param similarityScore
* @param support
* @param resource
*/
public FoundDBpediaResource(String surfaceForm, int offset, double similarityScore, int support, URI resource) {
this.begin = offset;
this.end = offset + surfaceForm.length();
Expand All @@ -23,6 +32,13 @@ public FoundDBpediaResource(String surfaceForm, int offset, double similaritySco
this.resource = resource;
}


/**
* constructor create from JSON
*
* @param jsonElement
* @throws URISyntaxException
*/
public FoundDBpediaResource(JsonElement jsonElement) throws URISyntaxException {
this(jsonElement.getAsJsonObject().get("surfaceForm").getAsString(),
jsonElement.getAsJsonObject().get("offset").getAsInt(),
Expand All @@ -31,22 +47,47 @@ public FoundDBpediaResource(JsonElement jsonElement) throws URISyntaxException {
new URI(jsonElement.getAsJsonObject().get("URI").getAsString()));
}

/**
* get begin index
*
* @return
*/
public int getBegin() {
return begin;
}

/**
* get end index
*
* @return
*/
public int getEnd() {
return end;
}

/**
* get DBpedia resource
*
* @return
*/
public URI getResource() {
return resource;
}

/**
* get support score
*
* @return
*/
public int getSupport() {
return support;
}


/**
* get similarity score
*
* @return
*/
public double getSimilarityScore() {
return similarityScore;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package eu.wdaqua.qanary.component.dbpediaspotlight.ned.exceptions;

/**
* exception thrown when the DBpedia Spotlight service is not available
*/
public class DBpediaSpotlightServiceNotAvailable extends Exception {
private static final long serialVersionUID = 1L;

/**
* constructor
*
* @param message
*/
public DBpediaSpotlightServiceNotAvailable(String message) {
super(message);
}
Expand Down
4 changes: 2 additions & 2 deletions qanary-component-QB-BirthDataWikidata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-QB-BirthDataWikidata</artifactId>
<version>3.4.1</version>
<version>3.4.4</version>
<parent>
<groupId>eu.wdaqua.qanary</groupId>
<artifactId>qa.qanarycomponent-parent</artifactId>
Expand Down Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core-jakarta</artifactId>
<version>2.2.16</version>
<version>2.2.22</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
this.myQuestion = myQanaryQuestion.getTextualRepresentation(); // get the question as String

// STEP 1-3 have two options

QanaryMessage qanaryMessageNew = myQanaryMessage;
// first, try to use a named entity annotation because it is more precise if it
// works, then stop
myQanaryMessage = this.processForExistingNamedEntity(myQanaryMessage);
if (myQanaryMessage != null) {
qanaryMessageNew = this.processForExistingNamedEntity(myQanaryMessage);
if (qanaryMessageNew != null) {
logger.info("Found a named entity annotation. Processing finished.");
return myQanaryMessage;
return qanaryMessageNew;
}

// second, let's try to find a firstname and lastname, if that works we stop
myQanaryMessage = this.processForFirstNameAndLastName(myQanaryMessage);
if( myQanaryMessage != null ) {
logger.info("Found firstname and lastname. Processing finished.");
return myQanaryMessage;
}
// second, let's try to find a firstname and lastname, if that works we stop
qanaryMessageNew = this.processForFirstNameAndLastName(myQanaryMessage);
if( qanaryMessageNew != null ) {
logger.info("Found firstname and lastname. Processing finished.");
return qanaryMessageNew;
}

logger.warn("Nothing could be done here.");
return myQanaryMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ WHERE {
?annotation qa:score ?annotationScore .
?annotation oa:hasTarget ?target .

FILTER (?wikidataResource = ?value)
FILTER (REGEX(?wikidataResource,?value, "i"))

?target oa:hasSource ?source .
?target oa:hasSelector ?textSelector .
?textSelector rdf:type oa:TextPositionSelector .
?textSelector oa:start ?start .
?textSelector oa:end ?end .
}
ORDER BY DESC(?annotationScore)
ORDER BY DESC(?annotationScore)
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ public List<String> fetchEntitiesAndCreateQueries(QanaryQuestion qanaryQuestion,
public List<String> createQueries(QanaryQuestion qanaryQuestion, List<String> queries) throws Exception {
List<String> createdQueries = new ArrayList<>();

logger.info("task: compute {} queries", queries.size());
for (int i = 0; i > queries.size(); i++) {
createdQueries.add(getInsertQuery(qanaryQuestion, queries.get(i), i));
String createdInsertQuery = getInsertQuery(qanaryQuestion, queries.get(i), i);
logger.info("created INSERT query: {}", createdInsertQuery);
createdQueries.add(createdInsertQuery);
}
return createdQueries;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.sparql.engine.binding.Binding;
import org.junit.Ignore;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -209,10 +211,15 @@ public void setup() throws URISyntaxException, SparqlQueryFailed {
}

@Test
@Disabled
public void createQueriesWithGivenEntities() throws Exception {
List<String> givenEntities = List.of("testCase1", "testCase2", "TESTcASE3");

List<String> result = queryBuilderDateOfDeathDBpedia.createQueries(qanaryQuestion, givenEntities);

for (String query: result) {
logger.info("computed query: {}", query);
}

assertEquals(3, result.size());
assertAll("Result Queries contain given Entities",
Expand Down Expand Up @@ -256,6 +263,7 @@ void setup() throws SparqlQueryFailed, URISyntaxException {
}

@Test
@Disabled
void fetchEntitiesAndCreateQueriesWithGivenResultSet() throws Exception {
List<QuerySolutionMap> querySolutionMaps = addQuerySolutionMapForTupleTestObject(tupleTestObjects);
resultSet = createResultSet(querySolutionMaps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public List<String> getSupportedLang() {
* implement this method encapsulating the functionality of your Qanary
* component, some helping notes w.r.t. the typical 3 steps of implementing a
* Qanary component are included in the method (you might remove all of them)
*
* @throws SparqlQueryFailed
*/
@Override
public QanaryMessage process(QanaryMessage myQanaryMessage) {
Expand Down
Loading

0 comments on commit 601c13d

Please sign in to comment.