Пример #1
0
 private List<Pair<List<Integer>, String>> predictFrames(
     Sentence sentence, List<List<Integer>> targets) {
   final List<Pair<List<Integer>, String>> idResult = Lists.newArrayList();
   for (List<Integer> targetTokenIdxs : targets) {
     final String frame = idModel.getBestFrame(targetTokenIdxs, sentence);
     idResult.add(Pair.of(targetTokenIdxs, frame));
   }
   return idResult;
 }
Пример #2
0
 public static Semafor getSemaforInstance(String modelDirectory)
     throws IOException, ClassNotFoundException, URISyntaxException {
   final String requiredDataFilename =
       new File(modelDirectory, REQUIRED_DATA_FILENAME).getAbsolutePath();
   final String alphabetFilename = new File(modelDirectory, ALPHABET_FILENAME).getAbsolutePath();
   final String frameElementMapFilename =
       new File(modelDirectory, FRAME_ELEMENT_MAP_FILENAME).getAbsolutePath();
   final String argModelFilename = new File(modelDirectory, ARG_MODEL_FILENAME).getAbsolutePath();
   // unpack required data
   final RequiredDataForFrameIdentification r = readObject(requiredDataFilename);
   final Set<String> allRelatedWords = r.getAllRelatedWords();
   final GraphBasedFrameIdentifier idModel = GraphBasedFrameIdentifier.getInstance(modelDirectory);
   final RoteSegmenter segmenter = new RoteSegmenter(allRelatedWords);
   System.err.println("Initializing alphabet for argument identification..");
   final Map<String, Integer> argIdFeatureIndex =
       DataPrep.readFeatureIndex(new File(alphabetFilename));
   final FEDict frameElementsForFrame = FEDict.fromFile(frameElementMapFilename);
   final Decoding decoder = Decoding.fromFile(argModelFilename, alphabetFilename);
   return new Semafor(
       allRelatedWords, frameElementsForFrame, segmenter, idModel, decoder, argIdFeatureIndex);
 }