Skip to content

Commit

Permalink
QB-BirthDataWikidata v3.4.0: ext. functionality
Browse files Browse the repository at this point in the history
* separated functionality: 1. use named entities that are linked, 2. use firstname and lastname annotations
* improved SPARQL queries
* added additional documentation
  • Loading branch information
anbo-de committed Jan 5, 2024
1 parent e4864ca commit 7412bbb
Show file tree
Hide file tree
Showing 8 changed files with 483 additions and 322 deletions.
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.3.7</version>
<version>3.4.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand All @@ -15,7 +15,7 @@
</parent>
<properties>
<java.version>17</java.version>
<qanary.version>[3.7.6,4.0.0)</qanary.version>
<qanary.version>[3.9.2,4.0.0)</qanary.version>
<docker.image.prefix>qanary</docker.image.prefix>
<docker.image.name>qanary-component-qb-birthdata-wikidata</docker.image.name>
<dockerfile-maven-version>1.4.13</dockerfile-maven-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"eu.wdaqua.qanary"})
@ComponentScan(basePackages = { "eu.wdaqua.qanary" })
/**
* basic class for wrapping functionality to a Qanary component
* note: there is no need to change something here
* basic class for wrapping functionality to a Qanary component note: there is
* no need to change something here
*/
public class Application {

Expand All @@ -29,18 +29,19 @@ public static void main(String[] args) {
}

/**
* this method is needed to make the QanaryComponent in this project known
* to the QanaryServiceController in the qanary_component-template
* this method is needed to make the QanaryComponent in this project known to
* the QanaryServiceController in the qanary_component-template
*
* @return
*/
@Bean
public QanaryComponent qanaryComponent(@Value("${spring.application.name}") final String applicationName) {
return new BirthDataQueryBuilder(applicationName);
}

@Bean
public BirthDataQueryBuilderController getBirthDataQueryBuilderController(BirthDataQueryBuilder myBirthDataQueryBuilder) {

@Bean
public BirthDataQueryBuilderController getBirthDataQueryBuilderController(
BirthDataQueryBuilder myBirthDataQueryBuilder) {
return new BirthDataQueryBuilderController(myBirthDataQueryBuilder);
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Update the port number
server.port=5555
spring.application.name=BirthDataQueryBuilderWikidata
spring.application.name=QB-BirthDataWikidata
spring.application.description=${spring.application.name} is a Qanary component for creating a Wikidata SPARQL query intended to find the birth place and date of people by firstname/lastname or Wikidata resource
# Update the URL of the Qanary pipeline
spring.boot.admin.url=http://localhost:8080
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# retrieve an annotation pointing to Wikidata entity from a text segment (TextSelector)
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX oa: <http://www.w3.org/ns/openannotation/core/>
PREFIX qa: <http://www.wdaqua.eu/qa#>
Expand All @@ -7,15 +8,18 @@ SELECT *
FROM ?graph
WHERE {
?annotation oa:hasBody ?wikidataResource .
# accept only Wikidata resources as it is a Wikidata Query Builder component
FILTER( REGEX(?wikidataResource, "^http://www.wikidata.org/entity/", "i"))
?annotation qa:score ?annotationScore .
?annotation oa:hasTarget ?target .
?annotation oa:annotatedBy ?annotator .
?target oa:hasSource ?source .
?target oa:hasSelector ?textSelector .
?textSelector rdf:type oa:TextPositionSelector .
?textSelector oa:start ?start .
?textSelector oa:end ?end .

# filter named entities that have particular start index in the given question
FILTER(?start = ?filterStart) .
# accept only Wikidata resources as it is a Wikidata Query Builder component
FILTER( REGEX(?wikidataResource, ?regexForResourceFilter, "i"))
}
ORDER BY DESC(?annotationScore)
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void filenameAnnotationsFilteredQueryTest() throws IOException {
bindingsForAnnotation.add("filterStart", ResourceFactory.createTypedLiteral(String.valueOf(5), XSDDatatype.XSDint));

String sparqlGetAnnotation = QanaryTripleStoreConnector.readFileFromResourcesWithMap(
TestConfiguration.FILENAME_ANNOTATIONS_FILTERED,
TestConfiguration.FILENAME_ANNOTATIONS_NAMED_ENTITY_FILTERED_FOR_WIKIDATA,
bindingsForAnnotation
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import eu.wdaqua.component.qb.birthdata.wikidata.BirthDataQueryBuilder;

@org.springframework.boot.test.context.TestConfiguration
public class TestConfiguration {
protected static final String FILENAME_ANNOTATIONS = "/queries/getAnnotation.rq";
protected static final String FILENAME_ANNOTATIONS_FILTERED = "/queries/getAnnotationFiltered.rq";
protected static final String FILENAME_WIKIDATA_BIRTHDATA_QUERY_PERSON = "/queries/getQuestionAnswerFromWikidataByPerson.rq";
protected static final String FILENAME_WIKIDATA_BIRTHDATA_QUERY_FIRST_AND_LASTNAME = "/queries/getQuestionAnswerFromWikidataByFirstnameLastname.rq";
protected static final String FILENAME_ANNOTATIONS = BirthDataQueryBuilder.FILENAME_ANNOTATIONS;
protected static final String FILENAME_ANNOTATIONS_NAMED_ENTITY_FILTERED_FOR_WIKIDATA = BirthDataQueryBuilder.FILENAME_ANNOTATIONS_NAMED_ENTITY_FILTERED_FOR_WIKIDATA;
protected static final String FILENAME_WIKIDATA_BIRTHDATA_QUERY_PERSON = BirthDataQueryBuilder.FILENAME_WIKIDATA_BIRTHDATA_QUERY_PERSON;
protected static final String FILENAME_WIKIDATA_BIRTHDATA_QUERY_FIRST_AND_LASTNAME = BirthDataQueryBuilder.FILENAME_WIKIDATA_BIRTHDATA_QUERY_FIRST_AND_LASTNAME;

/**
* get the defined SPARQL query and remove all control characters (like newline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ FROM <urn:graph>
WHERE
{ ?annotation oa:hasBody ?wikidataResource ;
qa:score ?annotationScore ;
oa:hasTarget ?target .
oa:hasTarget ?target ;
oa:annotatedBy ?annotator .
?target oa:hasSource <urn:source> ;
oa:hasSelector ?textSelector .
?textSelector
rdf:type oa:TextPositionSelector ;
oa:start ?start ;
oa:end ?end
FILTER ( ?start = "5"^^<http://www.w3.org/2001/XMLSchema#int> )
FILTER regex(?wikidataResource, ?regexForResourceFilter, "i")
}
ORDER BY DESC(?annotationScore)

0 comments on commit 7412bbb

Please sign in to comment.