@Test public void testClassify() throws AnalysisException { List<Token<AffiliationLabel>> tokens = new ArrayList<Token<AffiliationLabel>>(); for (int i = 0; i < 5; i++) { tokens.add(new Token<AffiliationLabel>()); } tokens.get(0).setFeatures(Arrays.asList( "W=University", "IsUpperCase" )); tokens.get(1).setFeatures(Arrays.asList( "W=,", "IsSeparator" )); tokens.get(2).setFeatures(Arrays.asList( "W=Boston", "IsUpperCase", "KeywordCity" )); tokens.get(3).setFeatures(Arrays.asList( "W=,", "IsSeparator" )); tokens.get(4).setFeatures(Arrays.asList( "W=USA", "IsAllCapital", "KeywordCountry" )); new AffiliationCRFTokenClassifier().classify(tokens); for (Token<AffiliationLabel> token : tokens) { assertNotNull(token.getLabel()); } }
@Override public void classify(List<Token<AffiliationLabel>> tokens) throws AnalysisException { if (tokens == null || tokens.isEmpty()) { return; } for (Token<AffiliationLabel> token : tokens) { if (token.getLabel() == null) { token.setLabel(AffiliationLabel.TEXT); } } String data = GrmmUtils.toGrmmInput(tokens, DEFAULT_NEIGHBOR_INFLUENCE); Pipe pipe = model.getInputPipe(); InstanceList instanceList = new InstanceList(pipe); instanceList.add(getLineIterator(data)); LabelsSequence labelsSequence = null; try { labelsSequence = (LabelsSequence) model.getBestLabels(instanceList).get(0); } catch (ArrayIndexOutOfBoundsException ex) { throw new AnalysisException("ACRF model can't recognize some of the labels."); } for (int i = 0; i < labelsSequence.size(); i++) { tokens.get(i).setLabel(AffiliationLabel.valueOf(labelsSequence.get(i).toString())); } enhanceLabels(tokens); }
AffiliationCRFTokenClassifier implements TokenClassifier<Token<AffiliationLabel>> { @Override public void classify(List<Token<AffiliationLabel>> tokens) throws AnalysisException { if (tokens == null || tokens.isEmpty()) { return; } for (Token<AffiliationLabel> token : tokens) { if (token.getLabel() == null) { token.setLabel(AffiliationLabel.TEXT); } } String data = GrmmUtils.toGrmmInput(tokens, DEFAULT_NEIGHBOR_INFLUENCE); Pipe pipe = model.getInputPipe(); InstanceList instanceList = new InstanceList(pipe); instanceList.add(getLineIterator(data)); LabelsSequence labelsSequence = null; try { labelsSequence = (LabelsSequence) model.getBestLabels(instanceList).get(0); } catch (ArrayIndexOutOfBoundsException ex) { throw new AnalysisException("ACRF model can't recognize some of the labels."); } for (int i = 0; i < labelsSequence.size(); i++) { tokens.get(i).setLabel(AffiliationLabel.valueOf(labelsSequence.get(i).toString())); } enhanceLabels(tokens); } }
AffiliationCRFTokenClassifier implements TokenClassifier<Token<AffiliationLabel>> { @Override public void classify(List<Token<AffiliationLabel>> tokens) throws AnalysisException { if (tokens == null || tokens.isEmpty()) { return; } for (Token<AffiliationLabel> token : tokens) { if (token.getLabel() == null) { token.setLabel(AffiliationLabel.TEXT); } } String data = GrmmUtils.toGrmmInput(tokens, DEFAULT_NEIGHBOR_INFLUENCE); Pipe pipe = model.getInputPipe(); InstanceList instanceList = new InstanceList(pipe); instanceList.add(getLineIterator(data)); LabelsSequence labelsSequence = null; try { labelsSequence = (LabelsSequence) model.getBestLabels(instanceList).get(0); } catch (ArrayIndexOutOfBoundsException ex) { throw new AnalysisException("ACRF model can't recognize some of the labels."); } for (int i = 0; i < labelsSequence.size(); i++) { tokens.get(i).setLabel(AffiliationLabel.valueOf(labelsSequence.get(i).toString())); } enhanceLabels(tokens); } AffiliationCRFTokenClassifier(InputStream modelInputStream);  AffiliationCRFTokenClassifier(); }
AffiliationCRFTokenClassifier implements TokenClassifier<Token<AffiliationLabel>> { @Override public void classify(List<Token<AffiliationLabel>> tokens) throws AnalysisException { if (tokens == null || tokens.isEmpty()) { return; } for (Token<AffiliationLabel> token : tokens) { if (token.getLabel() == null) { token.setLabel(AffiliationLabel.TEXT); } } String data = GrmmUtils.toGrmmInput(tokens, DEFAULT_NEIGHBOR_INFLUENCE); Pipe pipe = model.getInputPipe(); InstanceList instanceList = new InstanceList(pipe); instanceList.add(getLineIterator(data)); LabelsSequence labelsSequence = null; try { labelsSequence = (LabelsSequence) model.getBestLabels(instanceList).get(0); } catch (ArrayIndexOutOfBoundsException ex) { throw new AnalysisException("ACRF model can't recognize some of the labels."); } for (int i = 0; i < labelsSequence.size(); i++) { tokens.get(i).setLabel(AffiliationLabel.valueOf(labelsSequence.get(i).toString())); } enhanceLabels(tokens); } AffiliationCRFTokenClassifier(InputStream modelInputStream);  AffiliationCRFTokenClassifier(); @Override void classify(List<Token<AffiliationLabel>> tokens); }
AffiliationCRFTokenClassifier implements TokenClassifier<Token<AffiliationLabel>> { @Override public void classify(List<Token<AffiliationLabel>> tokens) throws AnalysisException { if (tokens == null || tokens.isEmpty()) { return; } for (Token<AffiliationLabel> token : tokens) { if (token.getLabel() == null) { token.setLabel(AffiliationLabel.TEXT); } } String data = GrmmUtils.toGrmmInput(tokens, DEFAULT_NEIGHBOR_INFLUENCE); Pipe pipe = model.getInputPipe(); InstanceList instanceList = new InstanceList(pipe); instanceList.add(getLineIterator(data)); LabelsSequence labelsSequence = null; try { labelsSequence = (LabelsSequence) model.getBestLabels(instanceList).get(0); } catch (ArrayIndexOutOfBoundsException ex) { throw new AnalysisException("ACRF model can't recognize some of the labels."); } for (int i = 0; i < labelsSequence.size(); i++) { tokens.get(i).setLabel(AffiliationLabel.valueOf(labelsSequence.get(i).toString())); } enhanceLabels(tokens); } AffiliationCRFTokenClassifier(InputStream modelInputStream);  AffiliationCRFTokenClassifier(); @Override void classify(List<Token<AffiliationLabel>> tokens);  }