001/** 002 * 003 */ 004package org.dllearner.algorithms.isle.index; 005 006import java.io.Serializable; 007import java.util.ArrayList; 008import java.util.List; 009 010/** 011 * A (non-semantic) annotation which represents an entity in a document by its offset and length. 012 * @author Lorenz Buehmann 013 * 014 */ 015public class Annotation implements Serializable{ 016 017 private Document referencedDocument; 018 private ArrayList<Token> tokens; 019 private String matchedString; 020 021 public String getMatchedString() { 022 return matchedString; 023 } 024 025 public void setMatchedString(String matchedString) { 026 this.matchedString = matchedString; 027 } 028 029 public Annotation(Document referencedDocument, List<Token> tokens) { 030 this.referencedDocument = referencedDocument; 031 this.tokens = new ArrayList<>(tokens); 032 } 033 034 public Document getReferencedDocument() { 035 return referencedDocument; 036 } 037 038 /** 039 * @return the tokens 040 */ 041 public ArrayList<Token> getTokens() { 042 return tokens; 043 } 044 045 public String getString(){ 046 StringBuilder sb = new StringBuilder(); 047 for (Token t : tokens) { 048 if (sb.length() > 0) { 049 sb.append(" "); 050 } 051 sb.append(t.getStemmedForm()); 052 } 053 return sb.toString(); 054 } 055 056 @Override 057 public boolean equals(Object o) { 058 if (this == o) { 059 return true; 060 } 061 if (o == null || getClass() != o.getClass()) { 062 return false; 063 } 064 065 Annotation that = (Annotation) o; 066 067 if (matchedString != null ? !matchedString.equals(that.matchedString) : that.matchedString != null) { 068 return false; 069 } 070 if (referencedDocument != null ? !referencedDocument.equals(that.referencedDocument) : 071 that.referencedDocument != null) { 072 return false; 073 } 074 if (tokens != null ? !tokens.equals(that.tokens) : that.tokens != null) { 075 return false; 076 } 077 078 return true; 079 } 080 081 @Override 082 public int hashCode() { 083 int result = referencedDocument != null ? referencedDocument.hashCode() : 0; 084 result = 31 * result + (tokens != null ? tokens.hashCode() : 0); 085 result = 31 * result + (matchedString != null ? matchedString.hashCode() : 0); 086 return result; 087 } 088 089 /* (non-Javadoc) 090 * @see java.lang.Object#toString() 091 */ 092 @Override 093 public String toString() { 094 return getString(); 095 } 096}