You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2013/05/16 12:04:42 UTC
svn commit: r1483284 - in
/stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking:
Entity.java impl/EntityLinker.java impl/LinkingStateAware.java
Author: rwesten
Date: Thu May 16 10:04:42 2013
New Revision: 1483284
URL: http://svn.apache.org/r1483284
Log:
STANBOL-1070: addition of the LinkingStateAware extension point for the EntityLinker; implemented hasCode, equals and toString for the Entity class
Added:
stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/LinkingStateAware.java (with props)
Modified:
stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/Entity.java
stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/EntityLinker.java
Modified: stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/Entity.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/Entity.java?rev=1483284&r1=1483283&r2=1483284&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/Entity.java (original)
+++ stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/Entity.java Thu May 16 10:04:42 2013
@@ -35,7 +35,7 @@ import org.apache.commons.collections.it
* {@link EntitySearcher} implementations that do support rankings for
* entities SHOULD override the {@link #getEntityRanking()} method.
*/
-public class Entity {
+public class Entity implements Comparable<Entity>{
protected static final LiteralFactory lf = LiteralFactory.getInstance();
@@ -68,13 +68,13 @@ public class Entity {
this.uri = uri;
this.data = data;
}
- public UriRef getUri() {
+ public final UriRef getUri() {
return uri;
}
- public String getId(){
+ public final String getId(){
return uri.getUnicodeString();
}
- public MGraph getData() {
+ public final MGraph getData() {
return data;
}
@SuppressWarnings("unchecked")
@@ -96,4 +96,35 @@ public class Entity {
public Float getEntityRanking(){
return null;
}
+ /**
+ * Uses the hascode of the {@link #getUri() URI}
+ */
+ @Override
+ public int hashCode() {
+ return uri.hashCode();
+ }
+ /**
+ * Checks if the two Entities do have the same {@link #getUri() URI}
+ */
+ @Override
+ public boolean equals(Object other) {
+ return other instanceof Entity && ((Entity)other).uri.equals(uri);
+ }
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("Entity[uri: ").append(uri.getUnicodeString());
+ Float entityRanking = getEntityRanking();
+ if(entityRanking != null){
+ sb.append(" | ranking: ").append(entityRanking);
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+ /**
+ * Compares Entities based on their {@link #getUri()}
+ */
+ @Override
+ public int compareTo(Entity other) {
+ return uri.getUnicodeString().compareTo(other.uri.getUnicodeString());
+ }
}
\ No newline at end of file
Modified: stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/EntityLinker.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/EntityLinker.java?rev=1483284&r1=1483283&r2=1483284&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/EntityLinker.java (original)
+++ stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/EntityLinker.java Thu May 16 10:04:42 2013
@@ -45,6 +45,7 @@ import org.apache.stanbol.enhancer.engin
import org.apache.stanbol.enhancer.engines.entitylinking.impl.ProcessingState.TokenData;
import org.apache.stanbol.enhancer.engines.entitylinking.impl.Suggestion.MATCH;
import org.apache.stanbol.enhancer.nlp.model.AnalysedText;
+import org.apache.stanbol.enhancer.nlp.model.Section;
import org.apache.stanbol.enhancer.nlp.model.Token;
import org.apache.stanbol.enhancer.servicesapi.rdf.NamespaceEnum;
import org.slf4j.Logger;
@@ -70,6 +71,8 @@ public class EntityLinker {
private Integer lookupLimit;
private LabelTokenizer labelTokenizer;
+
+ private LinkingStateAware linkingStateAware;
public EntityLinker(AnalysedText analysedText, String language,
@@ -77,6 +80,13 @@ public class EntityLinker {
EntitySearcher entitySearcher,
EntityLinkerConfig linkerConfig,
LabelTokenizer labelTokenizer) {
+ this(analysedText,language,textProcessingConfig,entitySearcher,linkerConfig,labelTokenizer,null);
+ }
+ public EntityLinker(AnalysedText analysedText, String language,
+ LanguageProcessingConfig textProcessingConfig,
+ EntitySearcher entitySearcher,
+ EntityLinkerConfig linkerConfig,
+ LabelTokenizer labelTokenizer, LinkingStateAware linkingStateAware) {
//this.analysedText = analysedText;
this.entitySearcher = entitySearcher;
this.linkerConfig = linkerConfig;
@@ -84,13 +94,27 @@ public class EntityLinker {
this.labelTokenizer = labelTokenizer;
this.state = new ProcessingState(analysedText,language,textProcessingConfig);
this.lookupLimit = Math.max(10,linkerConfig.getMaxSuggestions()*2);
+ this.linkingStateAware = linkingStateAware;
}
/**
* Steps over the sentences, chunks, tokens of the {@link #sentences}
*/
public void process() throws EntitySearcherException {
//int debugedIndex = 0;
+ Section sentence = null;
while(state.next()) {
+ //STANBOL-1070: added linkingStateAware callbacks for components that
+ // need to react on the state of the Linking process
+ if(linkingStateAware != null){
+ if(!state.getSentence().equals(sentence)){
+ if(sentence != null){
+ linkingStateAware.endSection(sentence);
+ }
+ sentence = state.getSentence(); //set the next sentence
+ linkingStateAware.startSection(sentence); //notify its start
+ }
+ linkingStateAware.startToken(state.getToken().token); //notify the current token
+ }
TokenData token = state.getToken();
if(log.isDebugEnabled()){
log.debug("--- preocess Token {}: {} (lemma: {}) linkable={}, matchable={} | chunk: {}",
@@ -271,8 +295,13 @@ public class EntityLinker {
//set the next token to process to the next word after the
//currently found suggestion
state.setConsumed(start+span-1);
+ } // else suggestions are empty
+ if(linkingStateAware != null){
+ linkingStateAware.endToken(state.getToken().token);
}
-
+ }
+ if(linkingStateAware != null && sentence != null){
+ linkingStateAware.endSection(sentence);
}
}
/**
Added: stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/LinkingStateAware.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/LinkingStateAware.java?rev=1483284&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/LinkingStateAware.java (added)
+++ stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/LinkingStateAware.java Thu May 16 10:04:42 2013
@@ -0,0 +1,40 @@
+package org.apache.stanbol.enhancer.engines.entitylinking.impl;
+
+import org.apache.stanbol.enhancer.nlp.model.AnalysedText;
+import org.apache.stanbol.enhancer.nlp.model.Section;
+import org.apache.stanbol.enhancer.nlp.model.Sentence;
+import org.apache.stanbol.enhancer.nlp.model.Token;
+
+/**
+ * Provides callbacks form the {@link EntityLinker} about the currently
+ * processed Tokens.
+ * @author Rupert Westenthaler
+ *
+ */
+public interface LinkingStateAware {
+ /**
+ * Callback notifying that the {@link EntityLinker} has completed the
+ * linking for the parsed {@link Section} (as {@link Sentence} in case
+ * sentence annotations are present in the {@link AnalysedText}).
+ * @param sentence the completed section
+ */
+ void endSection(Section sentence);
+
+ /**
+ * Callback notifying that the {@link EntityLinker} has started to link a
+ * new section of the text
+ * @param sentence the completed section
+ */
+ void startSection(Section sentence);
+ /**
+ * The next {@link Token} to be processed by the {@link EntityLinker}
+ * @param token the token that will be processed next
+ */
+ void startToken(Token token);
+ /**
+ * The next {@link Token} to be processed by the {@link EntityLinker}
+ * @param token the token that will be processed next
+ */
+ void endToken(Token token);
+
+}
Propchange: stanbol/trunk/enhancement-engines/entitylinking/engine/src/main/java/org/apache/stanbol/enhancer/engines/entitylinking/impl/LinkingStateAware.java
------------------------------------------------------------------------------
svn:mime-type = text/plain