From: <lor...@us...> - 2013-10-03 08:53:10
|
Revision: 4114 http://sourceforge.net/p/dl-learner/code/4114 Author: lorenz_b Date: 2013-10-03 08:53:06 +0000 (Thu, 03 Oct 2013) Log Message: ----------- Moved WSD into separate package. Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/StructuralEntityContext.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/RandomWordSenseDisambiguation.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/SimpleWordSenseDisambiguation.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/StructureBasedWordSenseDisambiguation.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/WordSenseDisambiguation.java trunk/components-core/src/main/resources/log4j.properties Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/RandomWordSenseDisambiguation.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/SimpleWordSenseDisambiguation.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/WordSenseDisambiguation.java Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/RandomWordSenseDisambiguation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/RandomWordSenseDisambiguation.java 2013-10-03 08:50:57 UTC (rev 4113) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/RandomWordSenseDisambiguation.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2007-2013, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package org.dllearner.algorithms.isle; - -import java.util.Random; -import java.util.Set; - -import org.dllearner.algorithms.isle.index.Annotation; -import org.dllearner.algorithms.isle.index.SemanticAnnotation; -import org.dllearner.core.owl.Entity; -import org.semanticweb.owlapi.model.OWLOntology; - -/** - * Disambiguation by randomly selecting one of the candidates (baseline method). - * - * @author Jens Lehmann - * - */ -public class RandomWordSenseDisambiguation extends WordSenseDisambiguation { - - private Random random; - - public RandomWordSenseDisambiguation(OWLOntology ontology) { - super(ontology); - random = new Random(); - } - - @Override - public SemanticAnnotation disambiguate(Annotation annotation, - Set<Entity> candidateEntities) { - int pos = random.nextInt(candidateEntities.size()); - int i = 0; - for(Entity e : candidateEntities) - { - if (i == pos) { - return new SemanticAnnotation(annotation, e); - } - i++; - } - return null; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/SimpleWordSenseDisambiguation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/SimpleWordSenseDisambiguation.java 2013-10-03 08:50:57 UTC (rev 4113) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/SimpleWordSenseDisambiguation.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -1,107 +0,0 @@ -/** - * - */ -package org.dllearner.algorithms.isle; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.log4j.Logger; -import org.dllearner.algorithms.isle.index.Annotation; -import org.dllearner.algorithms.isle.index.SemanticAnnotation; -import org.dllearner.core.owl.Entity; -import org.dllearner.utilities.owl.OWLAPIConverter; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; -import org.semanticweb.owlapi.model.OWLAnnotationProperty; -import org.semanticweb.owlapi.model.OWLDataFactory; -import org.semanticweb.owlapi.model.OWLEntity; -import org.semanticweb.owlapi.model.OWLLiteral; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.util.IRIShortFormProvider; -import org.semanticweb.owlapi.util.SimpleIRIShortFormProvider; - -import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; - -/** - * @author Lorenz Buehmann - * - */ -public class SimpleWordSenseDisambiguation extends WordSenseDisambiguation{ - - - private static final Logger logger = Logger.getLogger(SimpleWordSenseDisambiguation.class.getName()); - - private IRIShortFormProvider sfp = new SimpleIRIShortFormProvider(); - private OWLDataFactory df = new OWLDataFactoryImpl(); - private OWLAnnotationProperty annotationProperty = df.getRDFSLabel(); - - /** - * @param ontology - */ - public SimpleWordSenseDisambiguation(OWLOntology ontology) { - super(ontology); - } - - /* (non-Javadoc) - * @see org.dllearner.algorithms.isle.WordSenseDisambiguation#disambiguate(org.dllearner.algorithms.isle.index.Annotation, java.util.Set) - */ - @Override - public SemanticAnnotation disambiguate(Annotation annotation, Set<Entity> candidateEntities) { - logger.debug("Linguistic annotations:\n" + annotation); - logger.debug("Candidate entities:" + candidateEntities); - String token = annotation.getToken().trim(); - //check if annotation token matches label of entity or the part behind #(resp. /) - for (Entity entity : candidateEntities) { - Set<String> labels = getLabels(entity); - for (String label : labels) { - if(label.equals(token)){ - logger.debug("Disambiguated entity: " + entity); - return new SemanticAnnotation(annotation, entity); - } - } - String shortForm = sfp.getShortForm(IRI.create(entity.getURI())); - if(annotation.equals(shortForm)){ - logger.debug("Disambiguated entity: " + entity); - return new SemanticAnnotation(annotation, entity); - } - } - return null; - } - - private Set<String> getLabels(Entity entity){ - Set<String> labels = new HashSet<String>(); - OWLEntity owlEntity = OWLAPIConverter.getOWLAPIEntity(entity); - Set<OWLAnnotationAssertionAxiom> axioms = ontology.getAnnotationAssertionAxioms(owlEntity.getIRI()); - for (OWLAnnotationAssertionAxiom annotation : axioms) { - if(annotation.getProperty().equals(annotationProperty)){ - if (annotation.getValue() instanceof OWLLiteral) { - OWLLiteral val = (OWLLiteral) annotation.getValue(); - labels.add(val.getLiteral()); - } - } - } - return labels; - } - - private Set<String> getRelatedWordPhrases(Entity entity){ - //add the labels if exist - Set<String> relatedWordPhrases = new HashSet<String>(); - OWLEntity owlEntity = OWLAPIConverter.getOWLAPIEntity(entity); - Set<OWLAnnotationAssertionAxiom> axioms = ontology.getAnnotationAssertionAxioms(owlEntity.getIRI()); - for (OWLAnnotationAssertionAxiom annotation : axioms) { - if(annotation.getProperty().equals(annotationProperty)){ - if (annotation.getValue() instanceof OWLLiteral) { - OWLLiteral val = (OWLLiteral) annotation.getValue(); - relatedWordPhrases.add(val.getLiteral()); - } - } - } - //add the short form of the URI if no labels are available - if(relatedWordPhrases.isEmpty()){ - relatedWordPhrases.add(sfp.getShortForm(IRI.create(entity.getURI()))); - } - return relatedWordPhrases; - } - -} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/StructuralEntityContext.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/StructuralEntityContext.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/StructuralEntityContext.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -0,0 +1,207 @@ +/** + * + */ +package org.dllearner.algorithms.isle; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.dllearner.core.owl.Entity; +import org.dllearner.utilities.owl.OWLAPIConverter; +import org.semanticweb.owlapi.model.AxiomType; +import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationProperty; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.model.OWLOntology; + +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + +import com.google.common.collect.Sets; + +/** + * @author Lorenz Buehmann + * + */ +public class StructuralEntityContext { + + private static OWLDataFactory df = new OWLDataFactoryImpl(); + private static Set<OWLAnnotationProperty> annotationProperties = Sets.newHashSet( + df.getRDFSLabel(), + df.getRDFSComment()); + private static Set<String> languages = Sets.newHashSet("en"); + + /** + * Returns a set of words that describe entities related to the given entity. + * @param ontology + * @param entity + * @return + */ + public static Set<String> getContextInNaturalLanguage(OWLOntology ontology, OWLEntity entity){ + Set<String> context = new HashSet<String>(); + + Set<OWLEntity> contextEntities = getContext(ontology, entity); + //add annotations for each entity + for (OWLEntity contextEntity : contextEntities) { + context.addAll(getAnnotations(ontology, contextEntity)); + } + + return context; + } + + /** + * Returns a set of words that describe entities related to the given entity. + * @param ontology + * @param entity + * @return + */ + public static Set<String> getContextInNaturalLanguage(OWLOntology ontology, Entity entity){ + Set<String> context = new HashSet<String>(); + + Set<OWLEntity> contextEntities = getContext(ontology, entity); + //add annotations for each entity + for (OWLEntity contextEntity : contextEntities) { + context.addAll(getAnnotations(ontology, contextEntity)); + } + + return context; + } + + /** + * Returns a set of entities that are structural related to the given entity. + * @param ontology + * @param entity + * @return + */ + public static Set<OWLEntity> getContext(OWLOntology ontology, OWLEntity entity){ + + if(entity.isOWLClass()){ + return getContext(ontology, entity.asOWLClass()); + } else if(entity.isOWLObjectProperty()){ + return getContext(ontology, entity.asOWLObjectProperty()); + } else if(entity.isOWLDataProperty()){ + return getContext(ontology, entity.asOWLDataProperty()); + } + + throw new UnsupportedOperationException("Unsupported entity type: " + entity); + } + + /** + * Returns a set of entities that are structural related to the given entity. + * @param ontology + * @param entity + * @return + */ + public static Set<OWLEntity> getContext(OWLOntology ontology, Entity entity){ + + OWLEntity owlEntity = OWLAPIConverter.getOWLAPIEntity(entity); + if(owlEntity.isOWLClass()){ + return getContext(ontology, owlEntity.asOWLClass()); + } else if(owlEntity.isOWLObjectProperty()){ + return getContext(ontology, owlEntity.asOWLObjectProperty()); + } else if(owlEntity.isOWLDataProperty()){ + return getContext(ontology, owlEntity.asOWLDataProperty()); + } + + throw new UnsupportedOperationException("Unsupported entity type: " + entity); + } + + public static Set<OWLEntity> getContext(OWLOntology ontology, OWLObjectProperty property){ + Set<OWLEntity> context = new HashSet<OWLEntity>(); + + Set<OWLAxiom> relatedAxioms = new HashSet<OWLAxiom>(); + relatedAxioms.addAll(ontology.getObjectSubPropertyAxiomsForSubProperty(property)); + relatedAxioms.addAll(ontology.getEquivalentObjectPropertiesAxioms(property)); + relatedAxioms.addAll(ontology.getObjectPropertyDomainAxioms(property)); + relatedAxioms.addAll(ontology.getObjectPropertyRangeAxioms(property)); + + for (OWLAxiom axiom : relatedAxioms) { + context.addAll(axiom.getSignature()); + } + + return context; + } + + public static Set<OWLEntity> getContext(OWLOntology ontology, OWLDataProperty property){ + Set<OWLEntity> context = new HashSet<OWLEntity>(); + + Set<OWLAxiom> relatedAxioms = new HashSet<OWLAxiom>(); + relatedAxioms.addAll(ontology.getDataSubPropertyAxiomsForSubProperty(property)); + relatedAxioms.addAll(ontology.getEquivalentDataPropertiesAxioms(property)); + relatedAxioms.addAll(ontology.getDataPropertyDomainAxioms(property)); + + for (OWLAxiom axiom : relatedAxioms) { + context.addAll(axiom.getSignature()); + } + + return context; + } + + public static Set<OWLEntity> getContext(OWLOntology ontology, OWLClass cls){ + Set<OWLEntity> context = new HashSet<OWLEntity>(); + + Set<OWLAxiom> relatedAxioms = new HashSet<OWLAxiom>(); + relatedAxioms.addAll(ontology.getSubClassAxiomsForSubClass(cls)); + relatedAxioms.addAll(ontology.getEquivalentClassesAxioms(cls)); + + //axioms where cls is domain of a property + Set<OWLAxiom> domainAxioms = new HashSet<OWLAxiom>(); + domainAxioms.addAll(ontology.getAxioms(AxiomType.OBJECT_PROPERTY_DOMAIN)); + domainAxioms.addAll(ontology.getAxioms(AxiomType.DATA_PROPERTY_DOMAIN)); + for (Iterator<OWLAxiom> iterator = domainAxioms.iterator(); iterator.hasNext();) { + OWLAxiom axiom = iterator.next(); + if(!axiom.getSignature().contains(cls)){ + iterator.remove(); + } + } + relatedAxioms.addAll(domainAxioms); + + //axioms where cls is range of a object property + Set<OWLAxiom> rangeAxioms = new HashSet<OWLAxiom>(); + rangeAxioms.addAll(ontology.getAxioms(AxiomType.OBJECT_PROPERTY_RANGE)); + for (Iterator<OWLAxiom> iterator = rangeAxioms.iterator(); iterator.hasNext();) { + OWLAxiom axiom = iterator.next(); + if(!axiom.getSignature().contains(cls)){ + iterator.remove(); + } + } + relatedAxioms.addAll(rangeAxioms); + + for (OWLAxiom axiom : relatedAxioms) { + context.addAll(axiom.getSignature()); + } + + return context; + } + + private static Set<String> getAnnotations(OWLOntology ontology, OWLEntity entity){ + Set<String> annotations = new HashSet<String>(); + Set<OWLAnnotationAssertionAxiom> axioms = ontology.getAnnotationAssertionAxioms(entity.getIRI()); + for (OWLAnnotationAssertionAxiom annotation : axioms) { + if(annotationProperties.contains(annotation.getProperty())){ + if (annotation.getValue() instanceof OWLLiteral) { + OWLLiteral val = (OWLLiteral) annotation.getValue(); + if(val.getLang() != null && !val.getLang().isEmpty()){ + if(languages.contains(val.getLang())){ + if(!val.getLiteral().isEmpty()){ + annotations.add(val.getLiteral()); + } + } + } else { + if(!val.getLiteral().isEmpty()){ + annotations.add(val.getLiteral()); + } + } + } + } + } + return annotations; + } + +} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/WordSenseDisambiguation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/WordSenseDisambiguation.java 2013-10-03 08:50:57 UTC (rev 4113) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/WordSenseDisambiguation.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -1,36 +0,0 @@ -package org.dllearner.algorithms.isle; - -import org.dllearner.algorithms.isle.index.Annotation; -import org.dllearner.algorithms.isle.index.Document; -import org.dllearner.algorithms.isle.index.SemanticAnnotation; -import org.dllearner.core.owl.Entity; -import org.semanticweb.owlapi.model.OWLOntology; - -import java.util.Set; - -/** - * Abstract class for the word sense disambiguation component. - * - * @author Daniel Fleischhacker - */ -public abstract class WordSenseDisambiguation { - OWLOntology ontology; - - /** - * Initializes the word sense disambiguation to use the given ontology. - * - * @param ontology the ontology to disambiguate on - */ - public WordSenseDisambiguation(OWLOntology ontology) { - this.ontology = ontology; - } - - /** - * Chooses the correct entity for the given annotation from a set of candidate entities. - * - * @param annotation the annotation to find entity for - * @param candidateEntities the set of candidate entities - * @return semantic annotation containing the given annotation and the chosen entity - */ - public abstract SemanticAnnotation disambiguate(Annotation annotation, Set<Entity> candidateEntities); -} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/RandomWordSenseDisambiguation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/RandomWordSenseDisambiguation.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/RandomWordSenseDisambiguation.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -0,0 +1,59 @@ +/** + * Copyright (C) 2007-2013, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.dllearner.algorithms.isle.wsd; + +import java.util.Random; +import java.util.Set; + +import org.dllearner.algorithms.isle.index.Annotation; +import org.dllearner.algorithms.isle.index.SemanticAnnotation; +import org.dllearner.core.owl.Entity; +import org.semanticweb.owlapi.model.OWLOntology; + +/** + * Disambiguation by randomly selecting one of the candidates (baseline method). + * + * @author Jens Lehmann + * + */ +public class RandomWordSenseDisambiguation extends WordSenseDisambiguation { + + private Random random; + + public RandomWordSenseDisambiguation(OWLOntology ontology) { + super(ontology); + random = new Random(); + } + + @Override + public SemanticAnnotation disambiguate(Annotation annotation, + Set<Entity> candidateEntities) { + int pos = random.nextInt(candidateEntities.size()); + int i = 0; + for(Entity e : candidateEntities) + { + if (i == pos) { + return new SemanticAnnotation(annotation, e); + } + i++; + } + return null; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/SimpleWordSenseDisambiguation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/SimpleWordSenseDisambiguation.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/SimpleWordSenseDisambiguation.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -0,0 +1,107 @@ +/** + * + */ +package org.dllearner.algorithms.isle.wsd; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.isle.index.Annotation; +import org.dllearner.algorithms.isle.index.SemanticAnnotation; +import org.dllearner.core.owl.Entity; +import org.dllearner.utilities.owl.OWLAPIConverter; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationProperty; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.util.IRIShortFormProvider; +import org.semanticweb.owlapi.util.SimpleIRIShortFormProvider; + +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + +/** + * @author Lorenz Buehmann + * + */ +public class SimpleWordSenseDisambiguation extends WordSenseDisambiguation{ + + + private static final Logger logger = Logger.getLogger(SimpleWordSenseDisambiguation.class.getName()); + + private IRIShortFormProvider sfp = new SimpleIRIShortFormProvider(); + private OWLDataFactory df = new OWLDataFactoryImpl(); + private OWLAnnotationProperty annotationProperty = df.getRDFSLabel(); + + /** + * @param ontology + */ + public SimpleWordSenseDisambiguation(OWLOntology ontology) { + super(ontology); + } + + /* (non-Javadoc) + * @see org.dllearner.algorithms.isle.WordSenseDisambiguation#disambiguate(org.dllearner.algorithms.isle.index.Annotation, java.util.Set) + */ + @Override + public SemanticAnnotation disambiguate(Annotation annotation, Set<Entity> candidateEntities) { + logger.debug("Linguistic annotations:\n" + annotation); + logger.debug("Candidate entities:" + candidateEntities); + String token = annotation.getToken().trim(); + //check if annotation token matches label of entity or the part behind #(resp. /) + for (Entity entity : candidateEntities) { + Set<String> labels = getLabels(entity); + for (String label : labels) { + if(label.equals(token)){ + logger.debug("Disambiguated entity: " + entity); + return new SemanticAnnotation(annotation, entity); + } + } + String shortForm = sfp.getShortForm(IRI.create(entity.getURI())); + if(annotation.equals(shortForm)){ + logger.debug("Disambiguated entity: " + entity); + return new SemanticAnnotation(annotation, entity); + } + } + return null; + } + + private Set<String> getLabels(Entity entity){ + Set<String> labels = new HashSet<String>(); + OWLEntity owlEntity = OWLAPIConverter.getOWLAPIEntity(entity); + Set<OWLAnnotationAssertionAxiom> axioms = ontology.getAnnotationAssertionAxioms(owlEntity.getIRI()); + for (OWLAnnotationAssertionAxiom annotation : axioms) { + if(annotation.getProperty().equals(annotationProperty)){ + if (annotation.getValue() instanceof OWLLiteral) { + OWLLiteral val = (OWLLiteral) annotation.getValue(); + labels.add(val.getLiteral()); + } + } + } + return labels; + } + + private Set<String> getRelatedWordPhrases(Entity entity){ + //add the labels if exist + Set<String> relatedWordPhrases = new HashSet<String>(); + OWLEntity owlEntity = OWLAPIConverter.getOWLAPIEntity(entity); + Set<OWLAnnotationAssertionAxiom> axioms = ontology.getAnnotationAssertionAxioms(owlEntity.getIRI()); + for (OWLAnnotationAssertionAxiom annotation : axioms) { + if(annotation.getProperty().equals(annotationProperty)){ + if (annotation.getValue() instanceof OWLLiteral) { + OWLLiteral val = (OWLLiteral) annotation.getValue(); + relatedWordPhrases.add(val.getLiteral()); + } + } + } + //add the short form of the URI if no labels are available + if(relatedWordPhrases.isEmpty()){ + relatedWordPhrases.add(sfp.getShortForm(IRI.create(entity.getURI()))); + } + return relatedWordPhrases; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/StructureBasedWordSenseDisambiguation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/StructureBasedWordSenseDisambiguation.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/StructureBasedWordSenseDisambiguation.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -0,0 +1,41 @@ +/** + * + */ +package org.dllearner.algorithms.isle.wsd; + +import java.util.Set; + +import org.dllearner.algorithms.isle.StructuralEntityContext; +import org.dllearner.algorithms.isle.index.Annotation; +import org.dllearner.algorithms.isle.index.SemanticAnnotation; +import org.dllearner.core.owl.Entity; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLOntology; + +/** + * @author Lorenz Buehmann + * + */ +public class StructureBasedWordSenseDisambiguation extends WordSenseDisambiguation{ + + /** + * @param ontology + */ + public StructureBasedWordSenseDisambiguation(OWLOntology ontology) { + super(ontology); + } + + /* (non-Javadoc) + * @see org.dllearner.algorithms.isle.wsd.WordSenseDisambiguation#disambiguate(org.dllearner.algorithms.isle.index.Annotation, java.util.Set) + */ + @Override + public SemanticAnnotation disambiguate(Annotation annotation, Set<Entity> candidateEntities) { + //TODO we should find the sentence in which the annotated token is contained in + String content = annotation.getReferencedDocument().getContent(); + for (Entity entity : candidateEntities) { + Set<String> entityContext = StructuralEntityContext.getContextInNaturalLanguage(ontology, entity); + } + return null; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/WordSenseDisambiguation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/WordSenseDisambiguation.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/wsd/WordSenseDisambiguation.java 2013-10-03 08:53:06 UTC (rev 4114) @@ -0,0 +1,35 @@ +package org.dllearner.algorithms.isle.wsd; + +import java.util.Set; + +import org.dllearner.algorithms.isle.index.Annotation; +import org.dllearner.algorithms.isle.index.SemanticAnnotation; +import org.dllearner.core.owl.Entity; +import org.semanticweb.owlapi.model.OWLOntology; + +/** + * Abstract class for the word sense disambiguation component. + * + * @author Daniel Fleischhacker + */ +public abstract class WordSenseDisambiguation { + OWLOntology ontology; + + /** + * Initializes the word sense disambiguation to use the given ontology. + * + * @param ontology the ontology to disambiguate on + */ + public WordSenseDisambiguation(OWLOntology ontology) { + this.ontology = ontology; + } + + /** + * Chooses the correct entity for the given annotation from a set of candidate entities. + * + * @param annotation the annotation to find entity for + * @param candidateEntities the set of candidate entities + * @return semantic annotation containing the given annotation and the chosen entity + */ + public abstract SemanticAnnotation disambiguate(Annotation annotation, Set<Entity> candidateEntities); +} Added: trunk/components-core/src/main/resources/log4j.properties =================================================================== --- trunk/components-core/src/main/resources/log4j.properties (rev 0) +++ trunk/components-core/src/main/resources/log4j.properties 2013-10-03 08:53:06 UTC (rev 4114) @@ -0,0 +1,17 @@ +# Direct log messages to stdout +# Root logger option +log4j.rootLogger=INFO,stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %p [%c] %L - %m%n +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} [%c] - %m%n + +#File Appender +log4j.appender.FA=org.apache.log4j.FileAppender +log4j.appender.FA.File=REX.log +log4j.appender.FA.layout=org.apache.log4j.PatternLayout +log4j.appender.FA.layout.ConversionPattern=%d{ABSOLUTE} %p [%c] %L - %m%n + + +log4j.category.org.dllearner.algorithms=DEBUG Property changes on: trunk/components-core/src/main/resources/log4j.properties ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |