Skip to content

Commit

Permalink
Added artificial clue, generates concepts from artificial clue
Browse files Browse the repository at this point in the history
  • Loading branch information
thePetrMarek committed Mar 3, 2016
1 parent ad732f1 commit 61f8a45
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Clue> clues = cluesToCheck(resultView);
List<Clue> 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
Expand Down Expand Up @@ -258,6 +259,13 @@ protected List<Clue> cluesToCheck(JCas resultView) {
return clues;
}

protected List<Clue> artificialCluesToCheck(JCas resultView){
List<Clue> 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) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cz/brmlab/yodaqa/flow/dashboard/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Question {
protected boolean finished = false;
protected List<QuestionConcept> 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;
Expand All @@ -48,8 +48,8 @@ public Question(String id, String text) {
public synchronized List<QuestionConcept> 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; }
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cz/brmlab/yodaqa/io/web/WebInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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", "*");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cz/brmlab/yodaqa/io/web/WebQuestionReader.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/typesystem/QuestionTypes_TS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@
<description>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.</description>
<supertypeName>cz.brmlab.yodaqa.model.Question.Clue</supertypeName>
</typeDescription>
<typeDescription>
<name>cz.brmlab.yodaqa.model.Question.ArtificialClue</name>
<description>Clue not generated by yodaQA but added by user.</description>
<supertypeName>cz.brmlab.yodaqa.model.Question.ClueNE</supertypeName>
</typeDescription>
<typeDescription>
<name>cz.brmlab.yodaqa.model.Question.Concept</name>
<description>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.</description>
Expand Down

0 comments on commit 61f8a45

Please sign in to comment.