public ResultAnswer answerQuestion(String question) throws IOException, QuestionNotSolveException { List retrieveData = null; ResultAnswer resultAnswer = null; Token[] tokens = SentenseUtil.formatNerWordInQuestion(question); tokens = SentenseUtil.optimizePosTags(tokens); try { /*-------------------------Step 2-------------------------------------------*/ List<TripleToken> list = extractTriple.extractTripleWordRelation(tokens); /*-------------------------Step 3-------------------------------------------*/ recognizer.identifyTripleTokens(list); EntityType entityTypeOfQuestion = recognizer.recognizeEntityOfQuestion(tokens); /*-------------------------Step 4-------------------------------------------*/ List<List<TripleToken>> groupTripleTokens = TripleToken.groupTripleTokens(list); String query = GenSQLQuery.genQuery(groupTripleTokens, entityTypeOfQuestion); retrieveData = RetrieveData.retrieveData(query, groupTripleTokens, entityTypeOfQuestion, 0, 999999); resultAnswer = new ResultAnswer(question, query, groupTripleTokens, entityTypeOfQuestion); resultAnswer.setRetrieveData(retrieveData); resultAnswer.setQuestionType(QuestionType.recognizeTypeOfQuestion(tokens)); } catch (Exception ex) { throw new QuestionNotSolveException(); } return resultAnswer; }
public ResultAnswer answerQuestion( ResultAnswer resultAnswer, String originValue, String replaceValue) throws IOException, QuestionNotSolveException { String question = resultAnswer.getQuestion(); System.out.println(resultAnswer.getQuestion()); String query = resultAnswer.getQuery(); List<List<TripleToken>> groupTripleTokens = resultAnswer.getGroupTripleTokens(); EntityType entityTypeOfQuestion = resultAnswer.getEntityTypeOfQuestion(); for (List<TripleToken> tripleTokens : groupTripleTokens) { for (TripleToken tripleToken : tripleTokens) { Token obj1 = tripleToken.getObj1(); Token obj2 = tripleToken.getObj2(); if (obj1.getValue().equals(originValue)) obj1.setValue(replaceValue); if (obj2.getValue().equals(originValue)) obj2.setValue(replaceValue); } } List retrieveData = RetrieveData.retrieveData(query, groupTripleTokens, entityTypeOfQuestion, 0, 100); question = question.replace(originValue, "\"" + replaceValue + "\""); question = question.replace("\"\"", "\""); resultAnswer.setQuestion(question); resultAnswer.setRetrieveData(retrieveData); return resultAnswer; }