From 61f8a453bb6baf6d172272a7255b20bc6dc99b4c Mon Sep 17 00:00:00 2001 From: ermrk Date: Thu, 3 Mar 2016 13:51:05 +0100 Subject: [PATCH] Added artificial clue, generates concepts from artificial clue --- .../analysis/question/CluesToConcepts.java | 18 +++++++++++++----- .../brmlab/yodaqa/flow/dashboard/Question.java | 8 ++++---- .../cz/brmlab/yodaqa/io/web/WebInterface.java | 6 +++--- .../yodaqa/io/web/WebQuestionReader.java | 8 ++++---- src/main/typesystem/QuestionTypes_TS.xml | 5 +++++ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/main/java/cz/brmlab/yodaqa/analysis/question/CluesToConcepts.java b/src/main/java/cz/brmlab/yodaqa/analysis/question/CluesToConcepts.java index 1f63de1f..6fb93768 100644 --- a/src/main/java/cz/brmlab/yodaqa/analysis/question/CluesToConcepts.java +++ b/src/main/java/cz/brmlab/yodaqa/analysis/question/CluesToConcepts.java @@ -17,6 +17,7 @@ import cz.brmlab.yodaqa.model.Question.ClueSubjectNE; import cz.brmlab.yodaqa.model.Question.ClueSubjectPhrase; import cz.brmlab.yodaqa.model.Question.QuestionInfo; +import cz.brmlab.yodaqa.model.Question.ArtificialClue; import org.apache.uima.UimaContext; import org.apache.uima.analysis_engine.AnalysisEngineProcessException; @@ -81,11 +82,11 @@ public void initialize(UimaContext aContext) throws ResourceInitializationExcept public void process(JCas resultView) throws AnalysisEngineProcessException { QuestionInfo qi = JCasUtil.selectSingle(resultView, QuestionInfo.class); - if (qi.getOnlyArtificialConcepts()){ - return; - } - - List clues = cluesToCheck(resultView); + List clues; + if (!qi.getOnlyArtificialConcepts()) + clues = cluesToCheck(resultView); + else + clues = artificialCluesToCheck(resultView); /* Try to generate more canonical labels for the clues * by linking them to enwiki articles and creating @@ -258,6 +259,13 @@ protected List cluesToCheck(JCas resultView) { return clues; } + protected List artificialCluesToCheck(JCas resultView){ + List clues = new ArrayList<>(); + for (Clue clue : JCasUtil.select(resultView, ArtificialClue.class)) + clues.add(clue); + return clues; + } + /** Produce a pretty label from sometimes-unwieldy enwiki article * name. */ protected String cookLabel(String clueLabel, String canonLabel) { diff --git a/src/main/java/cz/brmlab/yodaqa/flow/dashboard/Question.java b/src/main/java/cz/brmlab/yodaqa/flow/dashboard/Question.java index e500671c..95cf9a97 100644 --- a/src/main/java/cz/brmlab/yodaqa/flow/dashboard/Question.java +++ b/src/main/java/cz/brmlab/yodaqa/flow/dashboard/Question.java @@ -27,7 +27,7 @@ public class Question { protected boolean finished = false; protected List artificialConcepts = new ArrayList<>(); protected boolean hasOnlyArtificialConcept=false; - protected String clueText; + protected String artificialClueText; /* Generation counts for various fields above, incremented every * time they are modified. */ protected int gen_sources = 0; @@ -48,8 +48,8 @@ public Question(String id, String text) { public synchronized List getArtificialConcepts(){ return artificialConcepts; } /** @return if question is using artificial Concepts only */ public synchronized boolean getHasOnlyArtificialConcept(){ return hasOnlyArtificialConcept; } - - public synchronized String getClueText(){return clueText;} + /** @return text of artificial clue */ + public synchronized String getArtificialClueText(){return artificialClueText;} /** @return the summary */ public synchronized QuestionSummary getSummary() { return summary; } @@ -62,7 +62,7 @@ public synchronized void setSummary(QuestionSummary summary) { public synchronized void setHasOnlyArtificialConcept(boolean hasOnlyArtificialConcept) { this.hasOnlyArtificialConcept=hasOnlyArtificialConcept; } - public synchronized void setClueText(String clueText) {this.clueText=clueText;} + public synchronized void setArtificialClueText(String artificialClueText) {this.artificialClueText = artificialClueText;} public synchronized void addSnippet(AnsweringSnippet snippet) { snippets.put(snippet.getSnippetID(),snippet); diff --git a/src/main/java/cz/brmlab/yodaqa/io/web/WebInterface.java b/src/main/java/cz/brmlab/yodaqa/io/web/WebInterface.java index 089292b8..4b1f43c0 100644 --- a/src/main/java/cz/brmlab/yodaqa/io/web/WebInterface.java +++ b/src/main/java/cz/brmlab/yodaqa/io/web/WebInterface.java @@ -62,9 +62,9 @@ public Object handle(Request request, Response response) { q.setArtificialConcepts(artificialConcepts); q.setHasOnlyArtificialConcept(true); } - String clueText = request.queryParams("prewiousCorrectAnswer"); - if (clueText != null){ - q.setClueText(clueText); + String artificialClueText = request.queryParams("artificialClue"); + if (artificialClueText != null){ + q.setArtificialClueText(artificialClueText); } QuestionDashboard.getInstance().askQuestion(q); response.header("Access-Control-Allow-Origin", "*"); diff --git a/src/main/java/cz/brmlab/yodaqa/io/web/WebQuestionReader.java b/src/main/java/cz/brmlab/yodaqa/io/web/WebQuestionReader.java index c68d72ae..7dd6aa4d 100644 --- a/src/main/java/cz/brmlab/yodaqa/io/web/WebQuestionReader.java +++ b/src/main/java/cz/brmlab/yodaqa/io/web/WebQuestionReader.java @@ -1,6 +1,6 @@ package cz.brmlab.yodaqa.io.web; -import cz.brmlab.yodaqa.model.Question.ClueNE; +import cz.brmlab.yodaqa.model.Question.ArtificialClue; import cz.brmlab.yodaqa.model.Question.Concept; import de.tudarmstadt.ukp.dkpro.core.api.parameter.ComponentParameters; @@ -68,9 +68,9 @@ protected void initCas(JCas jcas, Question q) { } } - if (q.getClueText() != null) { - ClueNE clue = new ClueNE(jcas,0,0); - clue.setLabel(q.getClueText()); + if (q.getArtificialClueText() != null) { + ArtificialClue clue = new ArtificialClue(jcas,0,0); + clue.setLabel(q.getArtificialClueText()); clue.addToIndexes(); } } diff --git a/src/main/typesystem/QuestionTypes_TS.xml b/src/main/typesystem/QuestionTypes_TS.xml index 59f88bb6..3e999f69 100644 --- a/src/main/typesystem/QuestionTypes_TS.xml +++ b/src/main/typesystem/QuestionTypes_TS.xml @@ -224,6 +224,11 @@ Clue based on an arbitrary n-gram (sequence of n subsequent tokens). We generate these only when we have a good reason to, e.g. this n-gram matches some well-known entity label. cz.brmlab.yodaqa.model.Question.Clue + + cz.brmlab.yodaqa.model.Question.ArtificialClue + Clue not generated by yodaQA but added by user. + cz.brmlab.yodaqa.model.Question.ClueNE + cz.brmlab.yodaqa.model.Question.Concept Concept is basically a Wikipedia article, labelled by its full title and the label somehow occurring in the question text. This is a strong indicator of the question topic, which in turn helps choose appropriate information sources.