@Test public void testConvertFullNoDocument() throws Exception { String id = "id"; ExtractedDocumentMetadata result = NlmToDocumentWithBasicMetadataConverter.convertFull(id, null, "text"); assertNotNull(result); assertEquals(id, result.getId()); assertEquals("text", result.getText()); }
public static ExtractedDocumentMetadata convertFull(String id, Document source, String text) throws TransformationException { if (id == null) { throw new RuntimeException("unable to set null id"); } ExtractedDocumentMetadata.Builder builder = ExtractedDocumentMetadata.newBuilder(); builder.setId(id); builder.setText(text != null ? text : ""); if (source == null) { return builder.build(); } Element rootElement = source.getRootElement(); convertMeta(id, rootElement, builder); Map<String, Affiliation> affiliationMap = convertAffiliations(rootElement); List<String> affiliationIds = new ArrayList<String>(); if (!affiliationMap.isEmpty()) { List<Affiliation> affiliations = new ArrayList<Affiliation>(); for (Entry<String, Affiliation> entry : affiliationMap.entrySet()) { affiliationIds.add(entry.getKey()); affiliations.add(entry.getValue()); } builder.setAffiliations(affiliations); } List<Author> authors = convertAuthors(rootElement, affiliationIds); if (!authors.isEmpty()) { builder.setAuthors(authors); } List<ReferenceMetadata> refs = convertReferences(rootElement); if (!refs.isEmpty()) { builder.setReferences(refs); } return builder.build(); }
NlmToDocumentWithBasicMetadataConverter { public static ExtractedDocumentMetadata convertFull(String id, Document source, String text) throws TransformationException { if (id == null) { throw new RuntimeException("unable to set null id"); } ExtractedDocumentMetadata.Builder builder = ExtractedDocumentMetadata.newBuilder(); builder.setId(id); builder.setText(text != null ? text : ""); if (source == null) { return builder.build(); } Element rootElement = source.getRootElement(); convertMeta(id, rootElement, builder); Map<String, Affiliation> affiliationMap = convertAffiliations(rootElement); List<String> affiliationIds = new ArrayList<String>(); if (!affiliationMap.isEmpty()) { List<Affiliation> affiliations = new ArrayList<Affiliation>(); for (Entry<String, Affiliation> entry : affiliationMap.entrySet()) { affiliationIds.add(entry.getKey()); affiliations.add(entry.getValue()); } builder.setAffiliations(affiliations); } List<Author> authors = convertAuthors(rootElement, affiliationIds); if (!authors.isEmpty()) { builder.setAuthors(authors); } List<ReferenceMetadata> refs = convertReferences(rootElement); if (!refs.isEmpty()) { builder.setReferences(refs); } return builder.build(); } }
NlmToDocumentWithBasicMetadataConverter { public static ExtractedDocumentMetadata convertFull(String id, Document source, String text) throws TransformationException { if (id == null) { throw new RuntimeException("unable to set null id"); } ExtractedDocumentMetadata.Builder builder = ExtractedDocumentMetadata.newBuilder(); builder.setId(id); builder.setText(text != null ? text : ""); if (source == null) { return builder.build(); } Element rootElement = source.getRootElement(); convertMeta(id, rootElement, builder); Map<String, Affiliation> affiliationMap = convertAffiliations(rootElement); List<String> affiliationIds = new ArrayList<String>(); if (!affiliationMap.isEmpty()) { List<Affiliation> affiliations = new ArrayList<Affiliation>(); for (Entry<String, Affiliation> entry : affiliationMap.entrySet()) { affiliationIds.add(entry.getKey()); affiliations.add(entry.getValue()); } builder.setAffiliations(affiliations); } List<Author> authors = convertAuthors(rootElement, affiliationIds); if (!authors.isEmpty()) { builder.setAuthors(authors); } List<ReferenceMetadata> refs = convertReferences(rootElement); if (!refs.isEmpty()) { builder.setReferences(refs); } return builder.build(); } private  NlmToDocumentWithBasicMetadataConverter(); }
NlmToDocumentWithBasicMetadataConverter { public static ExtractedDocumentMetadata convertFull(String id, Document source, String text) throws TransformationException { if (id == null) { throw new RuntimeException("unable to set null id"); } ExtractedDocumentMetadata.Builder builder = ExtractedDocumentMetadata.newBuilder(); builder.setId(id); builder.setText(text != null ? text : ""); if (source == null) { return builder.build(); } Element rootElement = source.getRootElement(); convertMeta(id, rootElement, builder); Map<String, Affiliation> affiliationMap = convertAffiliations(rootElement); List<String> affiliationIds = new ArrayList<String>(); if (!affiliationMap.isEmpty()) { List<Affiliation> affiliations = new ArrayList<Affiliation>(); for (Entry<String, Affiliation> entry : affiliationMap.entrySet()) { affiliationIds.add(entry.getKey()); affiliations.add(entry.getValue()); } builder.setAffiliations(affiliations); } List<Author> authors = convertAuthors(rootElement, affiliationIds); if (!authors.isEmpty()) { builder.setAuthors(authors); } List<ReferenceMetadata> refs = convertReferences(rootElement); if (!refs.isEmpty()) { builder.setReferences(refs); } return builder.build(); } private  NlmToDocumentWithBasicMetadataConverter(); static ExtractedDocumentMetadata convertFull(String id, Document source, String text); static ExtractedDocumentMetadata createEmpty(String id); }
NlmToDocumentWithBasicMetadataConverter { public static ExtractedDocumentMetadata convertFull(String id, Document source, String text) throws TransformationException { if (id == null) { throw new RuntimeException("unable to set null id"); } ExtractedDocumentMetadata.Builder builder = ExtractedDocumentMetadata.newBuilder(); builder.setId(id); builder.setText(text != null ? text : ""); if (source == null) { return builder.build(); } Element rootElement = source.getRootElement(); convertMeta(id, rootElement, builder); Map<String, Affiliation> affiliationMap = convertAffiliations(rootElement); List<String> affiliationIds = new ArrayList<String>(); if (!affiliationMap.isEmpty()) { List<Affiliation> affiliations = new ArrayList<Affiliation>(); for (Entry<String, Affiliation> entry : affiliationMap.entrySet()) { affiliationIds.add(entry.getKey()); affiliations.add(entry.getValue()); } builder.setAffiliations(affiliations); } List<Author> authors = convertAuthors(rootElement, affiliationIds); if (!authors.isEmpty()) { builder.setAuthors(authors); } List<ReferenceMetadata> refs = convertReferences(rootElement); if (!refs.isEmpty()) { builder.setReferences(refs); } return builder.build(); } private  NlmToDocumentWithBasicMetadataConverter(); static ExtractedDocumentMetadata convertFull(String id, Document source, String text); static ExtractedDocumentMetadata createEmpty(String id); static final String EMPTY_META; }