-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement etymQuote model as a first model to get complex like quote …
…from etym #14
- Loading branch information
Showing
10 changed files
with
490 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/org/grobid/core/engines/EtymQuoteParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.grobid.core.engines; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.grobid.core.data.LabeledLexicalInformation; | ||
import org.grobid.core.engines.label.TaggingLabel; | ||
import org.grobid.core.features.FeatureVectorLexicalEntry; | ||
import org.grobid.core.layout.LayoutToken; | ||
import org.grobid.core.layout.LayoutTokenization; | ||
import org.grobid.core.tokenization.TaggingTokenCluster; | ||
import org.grobid.core.tokenization.TaggingTokenClusteror; | ||
import org.grobid.core.utilities.LayoutTokensUtil; | ||
import org.grobid.core.utilities.Pair; | ||
import org.grobid.core.utilities.TextUtilities; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
import static org.grobid.core.document.TEIDictionaryFormatter.createMyXMLString; | ||
import static org.grobid.core.engines.label.DictionaryBodySegmentationLabels.DICTIONARY_ENTRY_LABEL; | ||
import static org.grobid.service.DictionaryPaths.PATH_FULL_DICTIONARY; | ||
|
||
/** | ||
* Created by Med on 06.10.17. | ||
*/ | ||
public class EtymQuoteParser extends AbstractParser { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(FormParser.class); | ||
private static volatile FormParser instance; | ||
|
||
public EtymQuoteParser() { | ||
super(DictionaryModels.ETYM_QUOTE); | ||
} | ||
|
||
|
||
public static FormParser getInstance() { | ||
if (instance == null) { | ||
getNewInstance(); | ||
} | ||
return instance; | ||
} | ||
|
||
private static synchronized void getNewInstance() { | ||
instance = new FormParser(); | ||
} | ||
|
||
public StringBuilder processToTei(List<LayoutToken> etymEntry) { | ||
LabeledLexicalInformation labeledSense = process(etymEntry, PATH_FULL_DICTIONARY); | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
sb.append("<etym>").append("\n"); | ||
//I apply the form also to the sense to recognise the grammatical group, if any! | ||
|
||
for (Pair<List<LayoutToken>, String> entrySense : labeledSense.getLabels()) { | ||
String tokenSense = LayoutTokensUtil.normalizeText(entrySense.getA()); | ||
String labelSense = entrySense.getB(); | ||
|
||
String content = TextUtilities.HTMLEncode(tokenSense); | ||
content = content.replace("<lb/>", "<lb/>"); | ||
|
||
sb.append(createMyXMLString(labelSense.replaceAll("[<>]", ""), content)); | ||
|
||
} | ||
sb.append("</etym>").append("\n"); | ||
return sb; | ||
|
||
} | ||
|
||
public LabeledLexicalInformation process(List<LayoutToken> etymEntry, String parentTag) { | ||
LabeledLexicalInformation labeledLexicalEntry = new LabeledLexicalInformation(); | ||
|
||
LayoutTokenization layoutTokenization = new LayoutTokenization(etymEntry); | ||
|
||
String featSeg = FeatureVectorLexicalEntry.createFeaturesFromLayoutTokens(layoutTokenization.getTokenization(), DICTIONARY_ENTRY_LABEL).toString(); | ||
|
||
if (StringUtils.isNotBlank(featSeg)) { | ||
// Run the lexical entry model to label the features | ||
String modelOutput = label(featSeg); | ||
TaggingTokenClusteror clusteror = new TaggingTokenClusteror(DictionaryModels.ETYM, modelOutput, etymEntry); | ||
|
||
List<TaggingTokenCluster> clusters = clusteror.cluster(); | ||
|
||
for (TaggingTokenCluster cluster : clusters) { | ||
if (cluster == null) { | ||
continue; | ||
} | ||
TaggingLabel clusterLabel = cluster.getTaggingLabel(); | ||
Engine.getCntManager().i((TaggingLabel) clusterLabel); | ||
|
||
List<LayoutToken> concatenatedTokens = cluster.concatTokens(); | ||
String tagLabel = clusterLabel.getLabel(); | ||
|
||
labeledLexicalEntry.addLabel(new Pair(concatenatedTokens, tagLabel)); | ||
} | ||
} | ||
|
||
|
||
return labeledLexicalEntry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/grobid/core/engines/label/EtymQuoteLabels.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.grobid.core.engines.label; | ||
|
||
import org.grobid.core.engines.DictionaryModels; | ||
|
||
import static org.grobid.core.engines.label.DictionaryBodySegmentationLabels.PUNCTUATION_LABEL; | ||
|
||
/** | ||
* Created by Med on 06.10.17. | ||
*/ | ||
public class EtymQuoteLabels extends TaggingLabels { | ||
|
||
private EtymQuoteLabels() { | ||
super(); | ||
} | ||
public static final String SEG_ETYM_LABEL = "<seg>"; | ||
public static final String QUOTE_ETYM_LABEL = "<quote>"; | ||
|
||
public static final TaggingLabel ETYM_SEG = new TaggingLabelImpl(DictionaryModels.ETYM, SEG_ETYM_LABEL); | ||
public static final TaggingLabel ETYM_QUOTE = new TaggingLabelImpl(DictionaryModels.ETYM, QUOTE_ETYM_LABEL); | ||
public static final TaggingLabel FORM_OTHER = new TaggingLabelImpl(DictionaryModels.ETYM, OTHER_LABEL); | ||
public static final TaggingLabel FORM_PUNCTUATION = new TaggingLabelImpl(DictionaryModels.ETYM, PUNCTUATION_LABEL); | ||
|
||
static { | ||
|
||
register(ETYM_SEG); | ||
register(ETYM_QUOTE); | ||
register(FORM_PUNCTUATION); | ||
register(FORM_OTHER); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.