Пример #1
0
        @Override
        public void invoke(StringBuffer yytext, int start, DfaRun runner) {

          //            Gson gson = new GsonBuilder().setPrettyPrinting().create();
          //            String jsonText = gson.toJson(json);
          String jsonText = new Gson().toJson(json);

          yytext.replace(0, yytext.length(), jsonText);
          runner.collect = false;
        }
Пример #2
0
        @Override
        public void invoke(StringBuffer yytext, int start, DfaRun runner) {

          // Get start and end of sentence
          int startSentence = yytext.indexOf("<s id=");
          int endSentence = yytext.lastIndexOf("</s>") + 4;

          int realStart = yytext.indexOf(">", startSentence) + 1;
          int realEnd = endSentence - 4;

          // Get sentence with XML tags
          String sentence = yytext.substring(realStart, realEnd);

          // Get respective sentence from corpus
          Sentence s = corpus.getSentence(sentenceCounter);

          // Remove sentence tags and escape XML
          //            sentence = sentence.replaceAll("\\<.*?>", "");
          // sentence = StringEscapeUtils.escapeXml(sentence);
          yytext.replace(startSentence, endSentence, sentence);

          // Get final start and end of sentence
          int startChar = offset + yytext.indexOf(sentence);
          int endChar = startChar + sentence.length();

          // Generate sentence on stand-off format
          JSONSentence js = new JSONSentence(sentenceCounter + 1, startChar, endChar - 1, sentence);

          getAnnotations(s, sentence, js, startChar);

          json.add(js);

          // Remove processed input from input
          yytext.replace(0, endSentence, "");

          // Change state variables
          sentenceCounter++;

          offset = endChar;
          runner.collect = true;
        }