ReferenceExtractor implements Serializable { public List<Tuple2<String, ReferenceMetadata>> extractReferences(DocumentWrapper docWrapper, int maxSupportedCitationLength) { List<ReferenceMetadata> docReferences = docWrapper.getDocumentMetadata().getReferenceList(); return docReferences.stream() .filter(r->StringUtils.isNotBlank(r.getRawCitationText()) && r.getRawCitationText().length() <= maxSupportedCitationLength) .map(r->new Tuple2<String, ReferenceMetadata>(docWrapper.getDocumentMetadata().getKey(), r)) .collect(Collectors.toList()); }  List<Tuple2<String, ReferenceMetadata>> extractReferences(DocumentWrapper docWrapper, int maxSupportedCitationLength);  }
@Test public void extractReferences() { BasicMetadata basicMetadata = BasicMetadata.newBuilder().build(); ReferenceMetadata ref1 = createReference("Raw citation"); ReferenceMetadata ref2 = createReference(""); ReferenceMetadata ref3 = createReference("Raw citation number 3"); ReferenceMetadata ref4 = createReference("Raw citation 4"); DocumentMetadata docMetadata = DocumentMetadata.newBuilder() .setKey("KEY") .setBasicMetadata(basicMetadata) .addReference(ref1).addReference(ref2).addReference(ref3).addReference(ref4) .build(); DocumentWrapper docWrapper = DocumentWrapper.newBuilder().setRowId("ROW_ID").setDocumentMetadata(docMetadata).build(); List<Tuple2<String, ReferenceMetadata>> docIdReferences = referenceExtractor.extractReferences(docWrapper, 20); assertEquals(2, docIdReferences.size()); assertEquals(docMetadata.getKey(), docIdReferences.get(0)._1()); assertEquals(docMetadata.getKey(), docIdReferences.get(1)._1()); assertEquals(ref1, docIdReferences.get(0)._2()); assertEquals(ref4, docIdReferences.get(1)._2()); }