Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 3.1 KB

File metadata and controls

76 lines (57 loc) · 3.1 KB

NED based on GPT models of the OpenAI API

Intention

Receives a textual question, forwards it to OpenAI API and links them to the DBpedia knowledge graph.

Behavior

A web service is provided, too, to interactively test the functionality.

As a Qanary component, it reads the question and the annotations produced by upstream components from the Qanary triplestore (the shared process memory), performs its task — disambiguate recognised entity mentions and link them to a knowledge base — and writes the result back as standard Qanary (Web Annotation / qa:) annotations. See Input specification / Output specification below for the exact annotation contract.

Characteristics

  • Task type: Named Entity Disambiguation / Entity Linking (NED).

  • Knowledge base: DBpedia.

  • External service: https://dbpedia.org/sparql

  • Note: This component uses the Open AI API to identify Wikipedia resources in the given text, links it to the corresponding DBpedia resources, and stores it as annotations of type AnnotationOfInstance.

  • Requires credentials / network: wraps a remote, keyed service — its live tests need an API key and network access (build offline with -DskipTests).

Implementation

  • Language: Java (JDK 21).

  • Major frameworks: Spring Boot 3.5 (spring-boot-starter-parent); the Qanary component framework eu.wdaqua.qanary:qa.component 4.0.0 (transitively Spring Boot Admin client + Apache Jena 5); springdoc-openapi (Swagger UI); Gson.

  • Main component class: src/main/java/eu/wdaqua/qanary/component/ned/gpt/GptBasedNamedEntityDisambiguation.java (extends eu.wdaqua.qanary.component.QanaryComponent).

  • Tests: 2 test class(es) under src/test/java/ (QanaryServiceControllerTest.java, SwaggerUiAvailabilityTest.java).

Build and run

Targets the current Qanary framework 4.0.0 (Spring Boot 3, Java 21). Install the framework first (mvn install in the Qanary repository), then build with JDK 21:

JAVA_HOME=/path/to/jdk21 mvn clean package
docker build --build-arg JAR_FILE=target/qanary-component-ned-openai-gpt.jar -t qanary/qanary-component-ned-openai-gpt .

Input specification

Not applicable as the textual question is a default parameter

Output specification

@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .

<urn:qanary:output> a qa:AnnotationOfInstance .
<urn:qanary:output> oa:hasTarget [
    a   oa:SpecificResource;
        oa:hasSource    <urn:qanary:myQanaryQuestion> ;
        oa:hasSelector  [
            a oa:TextPositionSelector ;
            oa:start "19"^^xsd:nonNegativeInteger ;
            oa:end  "25"^^xsd:nonNegativeInteger
        ]
    ] .
<urn:qanary:output> oa:hasBody <urn:dbr:Resource> ;
    oa:annotatedBy <urn:qanary:GptBasedNamedEntityDisambiguation> ;
    oa:annotatedAt "2001-10-26T21:32:52"^^xsd:dateTime ;
    qa:score "0.5"^^xsd:decimal .