@Test public void testClassifyWithDocumentAffiliation() throws AnalysisException, TransformationException { String text = "Department of Oncology, Radiology and Clinical Immunology, Akademiska " + "Sjukhuset, Uppsala, Sweden"; DocumentAffiliation instance = new DocumentAffiliation(text); instance.setTokens(TOKENIZER.tokenize(instance.getRawText())); EXTRACTOR.calculateFeatures(instance); new AffiliationCRFTokenClassifier().classify(instance.getTokens()); assertEquals(AffiliationLabel.INST, instance.getTokens().get(0).getLabel()); assertEquals(AffiliationLabel.INST, instance.getTokens().get(1).getLabel()); assertEquals(AffiliationLabel.ADDR, instance.getTokens().get(12).getLabel()); assertEquals(AffiliationLabel.COUN, instance.getTokens().get(14).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);  }