OpinionExpression(final OpinionExpression oe, final HashMap<String, Term> terms) { this.polarity = oe.polarity; this.strength = oe.strength; this.subjectivity = oe.subjectivity; this.sentimentSemanticType = oe.sentimentSemanticType; this.sentimentProductFeature = oe.sentimentProductFeature; /* Copy span */ final Span<Term> span = oe.span; final List<Term> targets = span.getTargets(); final List<Term> copiedTargets = new ArrayList<Term>(); for (final Term term : targets) { final Term copiedTerm = terms.get(term.getId()); if (copiedTerm == null) { throw new IllegalStateException( "Term not found when copying opinion_expression"); } copiedTargets.add(copiedTerm); } if (span.hasHead()) { final Term copiedHead = terms.get(span.getHead().getId()); this.span = new Span<Term>(copiedTargets, copiedHead); } else { this.span = new Span<Term>(copiedTargets); } this.externalReferences = new ArrayList<ExternalRef>(); for (final ExternalRef externalRef : oe.getExternalRefs()) { this.externalReferences.add(new ExternalRef(externalRef)); } }
private static List<ExternalRef> getRefs(final Object annotation) { List<ExternalRef> refs = ImmutableList.of(); if (annotation instanceof Term) { refs = ((Term) annotation).getExternalRefs(); } else if (annotation instanceof Entity) { refs = ((Entity) annotation).getExternalRefs(); } else if (annotation instanceof Predicate) { refs = ((Predicate) annotation).getExternalRefs(); } else if (annotation instanceof Role) { refs = ((Role) annotation).getExternalRefs(); } else if (annotation instanceof Opinion) { refs = ((Opinion) annotation).getExternalRefs(); } else if (annotation instanceof OpinionExpression) { refs = ((OpinionExpression) annotation).getExternalRefs(); } else if (annotation instanceof OpinionTarget) { refs = ((OpinionTarget) annotation).getExternalRefs(); } else if (annotation instanceof OpinionHolder) { refs = ((OpinionHolder) annotation).getExternalRefs(); } else { throw new IllegalArgumentException("Unsupported annotation object: " + annotation); } return refs; }
if (!expression.getExternalRefs().isEmpty()) { opinionExpressionElem.addContent(externalReferencesToDOM(expression.getExternalRefs()));