@Override public BibEntry parseBibReference(String text) throws AnalysisException { try { Citation citation = CitationUtils.stringToCitation(text); String data = StringUtils.join(CitationUtils.citationToMalletInputFormat(citation), "\n"); ACRF model = readModel(); Pipe pipe = model.getInputPipe(); InstanceList instanceList = new InstanceList(pipe); instanceList.add(new LineGroupIterator(new StringReader(data), Pattern.compile ("\\s*"), true)); LabelsSequence labelSequence = (LabelsSequence)model.getBestLabels(instanceList).get(0); for (int i = 0; i < labelSequence.size(); i++) { citation.getTokens().get(i).setLabel(CitationTokenLabel.valueOf(labelSequence.get(i).toString())); } return CitationUtils.citationToBibref(citation); } catch (ClassNotFoundException ex) { throw new AnalysisException("Cannot parse reference", ex); } catch (IOException ex) { throw new AnalysisException("Cannot parse reference", ex); } }
public void testSerializable () throws IOException, ClassNotFoundException { LabelAlphabet dict = new LabelAlphabet (); Labels lbls1 = new Labels (new Label[] { dict.lookupLabel ("A"), dict.lookupLabel ("B"), }); Labels lbls2 = new Labels (new Label[] { dict.lookupLabel ("C"), dict.lookupLabel ("A"), }); LabelsSequence lblseq = new LabelsSequence (new Labels[] { lbls1, lbls2 }); LabelsSequence lblseq2 = (LabelsSequence) TestSerializable.cloneViaSerialization (lblseq); assertEquals (lblseq.size(), lblseq2.size()); assertEquals (lblseq.getLabels(0).toString(), lblseq2.getLabels(0).toString ()); assertEquals (lblseq.getLabels(1).toString(), lblseq2.getLabels(1).toString ()); }
LabelAlphabet dict = (LabelAlphabet) getTargetAlphabet (); LabelsSequence lblseq = (LabelsSequence) target; Label[] labelArray = new Label [lblseq.size()]; for (int i = 0; i < lblseq.size(); i++) { Labels lbls = lblseq.getLabels (i); if (lbls.size () != 1) throw new IllegalArgumentException ("Cannot convert Labels at position "+i+" : "+lbls);
public Instance pipe(Instance carrier) { LabelSequence lblseq = (LabelSequence) carrier.getTarget (); Labels[] lbls = new Labels [lblseq.size()]; Label lastLabel = lblseq.getLabelAtPosition(0); for (int i = 0; i < lblseq.size(); i++) { Label thisLabel = lblseq.getLabelAtPosition (i); if (offset) lbls [i] = new Labels (new Label[] { thisLabel, lastLabel }); if (!thisLabel.toString().equals (backgroundLabel)) lastLabel = thisLabel; if (!offset) lbls [i] = new Labels (new Label[] { thisLabel, lastLabel }); } carrier.setTarget (new LabelsSequence (lbls)); return carrier; }