001/**
002 * 
003 */
004package org.dllearner.algorithms.isle.index;
005
006import org.semanticweb.owlapi.model.OWLEntity;
007
008import java.util.HashSet;
009import java.util.Set;
010import java.util.stream.Collectors;
011
012/**
013 * @author Lorenz Buehmann
014 *
015 */
016public class AnnotatedTextDocument implements AnnotatedDocument{
017        
018        private TextDocument document;
019        private Set<SemanticAnnotation> annotations;
020        private Set<OWLEntity> entities;
021
022        
023        public AnnotatedTextDocument(TextDocument document, Set<SemanticAnnotation> annotations) {
024                this.document = document;
025                this.annotations = annotations;
026                
027                entities = annotations.stream()
028                                .map(SemanticAnnotation::getEntity)
029                                .collect(Collectors.toCollection(HashSet<OWLEntity>::new));
030        }
031
032        /* (non-Javadoc)
033         * @see org.dllearner.algorithms.isle.index.Document#getContent()
034         */
035        @Override
036        public String getContent() {
037                return document.getContent();
038        }
039
040        /* (non-Javadoc)
041         * @see org.dllearner.algorithms.isle.index.Document#getRawContent()
042         */
043        @Override
044        public String getRawContent() {
045                return document.getRawContent();
046        }
047        
048        /* (non-Javadoc)
049         * @see org.dllearner.algorithms.isle.index.Document#getPOSTaggedContent()
050         */
051        @Override
052        public String getPOSTaggedContent() {
053                return document.getPOSTaggedContent();
054        }
055
056        /* (non-Javadoc)
057         * @see org.dllearner.algorithms.isle.index.AnnotatedDocument#getContainedEntities()
058         */
059        @Override
060        public Set<OWLEntity> getContainedEntities() {
061                return entities;
062        }
063
064        /* (non-Javadoc)
065         * @see org.dllearner.algorithms.isle.index.AnnotatedDocument#getAnnotations()
066         */
067        @Override
068        public Set<SemanticAnnotation> getAnnotations() {
069                return annotations;
070        }
071
072        /* (non-Javadoc)
073         * @see org.dllearner.algorithms.isle.index.AnnotatedDocument#getEntityFrequency(org.dllearner.core.owl.Entity)
074         */
075        @Override
076        public int getEntityFrequency(OWLEntity entity) {
077                int cnt = 0;
078                for (SemanticAnnotation annotation : annotations) {
079                        if(annotation.getEntity().equals(entity)){
080                                cnt++;
081                        }
082                }
083                return cnt;
084        }
085        
086        /* (non-Javadoc)
087         * @see java.lang.Object#toString()
088         */
089        @Override
090        public String toString() {
091                return "Document:" + document.getContent() + "\nAnnotations:" + annotations;
092        }
093
094}