diff --git a/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/de-ud2-pos.map b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/de-ud2-pos.map new file mode 100644 index 0000000000..1fc4fdce6f --- /dev/null +++ b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/de-ud2-pos.map @@ -0,0 +1,23 @@ +# Universal Dependencies v2 POS tags + +__META_SOURCE_URL__=https://universaldependencies.org/u/pos/index.html +__META_TYPE_BASE__=de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos. + +*=POS +ADJ=POS_ADJ +ADP=POS_ADP +ADV=POS_ADV +AUX=POS_AUX +CCONJ=POS_CONJ +DET=POS_DET +INTJ=POS_INTJ +NOUN=POS_NOUN +NUM=POS_NUM +PART=POS_PART +PRON=POS_PRON +PROPN=POS_PROPN +PUNCT=POS_PUNCT +SCONJ=POS_SCONJ +SYM=POS_SYM +VERB=POS_VERB +X=POS_X diff --git a/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/en-ptb-emory-pos.map b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/en-ptb-emory-pos.map index 303ac44e58..b74c138e66 100644 --- a/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/en-ptb-emory-pos.map +++ b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/en-ptb-emory-pos.map @@ -1,127 +1,5 @@ -# Penn Treebank Tagset with Emory NLP extensions +# Penn Treebank Tagset with the extensions used by the Emory/ClearNLP models # -# Source (PTB 1): http://faculty.washington.edu/dillon/GramResources/penntable.html -# Source (PTB 2): http://www.clips.ua.ac.be/pages/mbsp-tags -# Source (ClearNLP): http://clear.colorado.edu/compsem/documents/treebank_guidelines.pdf -# Source (Emory NLP4J): https://github.com/emorynlp/nlp4j/blob/master/md/components/part_of_speech_tagging.md - -__META_TYPE_BASE__=de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos. - -*=POS -# punctuation mark, comma -,=POS_PUNCT --=POS_PUNCT -# punctuation mark, sentence closer -.=POS_PUNCT -;=POS_PUNCT -?=POS_PUNCT -\!=POS_PUNCT -``=POS_PUNCT -''=POS_PUNCT --LRB-=POS_PUNCT --RRB-=POS_PUNCT -# punctuation mark, colon -\:=POS_PUNCT -# contextual separator, left paren -(=POS_PUNCT -# contextual separator, right paren -)=POS_PUNCT -\#=POS_PUNCT -# 1. CC Coordinating conjunction -CC=POS_CONJ -# 2. CD Cardinal number -CD=POS_NUM -# 3. DT Determiner -DT=POS_DET -# 4. EX Existential there -EX=POS_DET -# 5. FW Foreign word -FW=POS_X -# 6. IN Preposition or subordinating conjunction -IN=POS_ADP -# 7. JJ Adjective -JJ=POS_ADJ -# 8. JJR Adjective, comparative -JJR=POS_ADJ -# 9. JJS Adjective, superlative -JJS=POS_ADJ -# 10. LS List item marker -LS=POS_X -# 11. MD Modal -MD=POS_VERB -# 12. NN Noun, singular or mass -NN=POS_NOUN -# 13. NNS Noun, plural -NNS=POS_NOUN -# 14. NP Proper noun, singular (PTB 1) -NP=POS_PROPN -# 14. NP Proper noun, singular (PTB 2) -NNP=POS_PROPN -# 15. NPS Proper noun, plural (PTB 1) -NPS=POS_PROPN -# 15. NPS Proper noun, plural (PTB 2) -NNPS=POS_PROPN -# 16. PDT Predeterminer -PDT=POS_DET -# 17. POS Possessive ending -POS=POS_X -# 18. PP Personal pronoun -PP=POS_PRON -PRP=POS_PRON -# 19. PP$ Possessive pronoun -PP$=POS_PRON -PRP$=POS_PRON -# 20. RB Adverb -RB=POS_ADV -# 21. RBR Adverb, comparative -RBR=POS_ADV -# 22. RBS Adverb, superlative -RBS=POS_ADV -# 23. RP Particle -RP=POS_ADP -SENT=POS_PUNCT -# 24. SYM Symbol -SYM=POS_SYM -# 25. TO to -TO=POS_ADP -# 26. UH Interjection -UH=POS_INTJ -# 27. VB Verb, base form -VB=POS_VERB -# 28. VBD Verb, past tense -VBD=POS_VERB -# 29. VBG Verb, gerund or present participle -VBG=POS_VERB -# 30. VBN Verb, past participle -VBN=POS_VERB -# 31. VBP Verb, non-3rd person singular present -VBP=POS_VERB -# 32. VBZ Verb, 3rd person singular present -VBZ=POS_VERB -# 33. WDT Wh-determiner -WDT=POS_DET -# 34. WP Wh-pronoun -WP=POS_PRON -# 35. WP$ Possessive wh-pronoun -WP$=POS_PRON -# 36. WRB Wh-adverb -WRB=POS_ADV - -# Additional tags in ClearNLP / EmoryNLP models -# HYPH - unbound hyphen (Warner et al., 2004) -HYPH=POS_PUNCT -# AFX - unbound affix (Warner et al., 2004) -AFX=POS_X -# GW - mistranscription (Taylor, 1996) -GW=POS_X -# XX - uninterpretable material (Mott et al., 2009) -XX=POS_X - -# Additional tags in EmoryNLP models -# ADD - Email -ADD=POS_X -# NFP - Superfluous punctuation -NFP=POS_PUNCT -# $ - Dollar -$=POS_PUNCT +# These are the same extensions as in the English Web Treebank (EWT). +__META_REDIRECT__=classpath:/org/dkpro/core/api/lexmorph/tagset/en-ptb-ewt-pos.map diff --git a/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/en-ptb-ewt-pos.map b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/en-ptb-ewt-pos.map new file mode 100644 index 0000000000..4b1b81436a --- /dev/null +++ b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/en-ptb-ewt-pos.map @@ -0,0 +1,140 @@ +# Penn Treebank Tagset with the extensions of the English Web Treebank (EWT) +# +# Used e.g. by the CoreNLP 4.x English POS tagger and dependency parser models. +# +# Source (PTB 1): http://faculty.washington.edu/dillon/GramResources/penntable.html +# Source (PTB 2): http://www.clips.ua.ac.be/pages/mbsp-tags +# Source: http://repository.upenn.edu/cis_reports/570/ + +__META_TYPE_BASE__=de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos. + +# punctuation mark, comma +,=POS_PUNCT +# punctuation mark, sentence closer +.=POS_PUNCT +# dollar +$=POS_PUNCT +# dash +-=POS_PUNCT +# semi-colon +;=POS_PUNCT +# question mark +?=POS_PUNCT +# exclamation mark +\!=POS_PUNCT +# opening quotes +``=POS_PUNCT +# closing quotes +''=POS_PUNCT +# punctuation mark, colon +\:=POS_PUNCT +# contextual separator, left paren +-LRB-=POS_PUNCT +# contextual separator, left paren +(=POS_PUNCT +# contextual separator, right paren +-RRB-=POS_PUNCT +# contextual separator, right paren +)=POS_PUNCT +\#=POS_PUNCT +# sentence end marker +SENT=POS_PUNCT +# 1. CC Coordinating conjunction +CC=POS_CONJ +# 2. CD Cardinal number +CD=POS_NUM +# 3. DT Determiner +DT=POS_DET +# 4. EX Existential there +EX=POS_DET +# 5. FW Foreign word +FW=POS_X +# 6. IN Preposition or subordinating conjunction +IN=POS_ADP +# 7. JJ Adjective +JJ=POS_ADJ +# 8. JJR Adjective, comparative +JJR=POS_ADJ +# 9. JJS Adjective, superlative +JJS=POS_ADJ +# 10. LS List item marker +LS=POS_X +# 11. MD Modal +MD=POS_VERB +# 12. NN Noun, singular or mass +NN=POS_NOUN +# 13. NNS Noun, plural +NNS=POS_NOUN +# 14. NP Proper noun, singular (PTB 1) +NP=POS_PROPN +# 14. NP Proper noun, singular (PTB 2) +NNP=POS_PROPN +# 15. NPS Proper noun, plural (PTB 1) +NPS=POS_PROPN +# 15. NPS Proper noun, plural (PTB 2) +NNPS=POS_PROPN +# 16. PDT Predeterminer +PDT=POS_DET +# 17. POS Possessive ending +POS=POS_X +# 18. PP Personal pronoun +PP=POS_PRON +PRP=POS_PRON +# 19. PP$ Possessive pronoun +PP$=POS_PRON +PRP$=POS_PRON +# 20. RB Adverb +RB=POS_ADV +# 21. RBR Adverb, comparative +RBR=POS_ADV +# 22. RBS Adverb, superlative +RBS=POS_ADV +# 23. RP Particle +RP=POS_ADP +# 24. SYM Symbol +SYM=POS_SYM +# 25. TO to +TO=POS_ADP +# 26. UH Interjection +UH=POS_INTJ +# 27. VB Verb, base form +VB=POS_VERB +# 28. VBD Verb, past tense +VBD=POS_VERB +# 29. VBG Verb, gerund or present participle +VBG=POS_VERB +# 30. VBN Verb, past participle +VBN=POS_VERB +# 31. VBP Verb, non-3rd person singular present +VBP=POS_VERB +# 32. VBZ Verb, 3rd person singular present +VBZ=POS_VERB +# 33. WDT Wh-determiner +WDT=POS_DET +# 34. WP Wh-pronoun +WP=POS_PRON +# 35. WP$ Possessive wh-pronoun +WP$=POS_PRON +# 36. WRB Wh-adverb +WRB=POS_ADV + +# Additional tags in the English Web Treebank +# +# Source: https://catalog.ldc.upenn.edu/LDC2012T13 (English Web Treebank guidelines) +# Source: https://universaldependencies.org/treebanks/en_ewt/index.html (XPOS) + +# ADD - e-mail address or URL +ADD=POS_X +# AFX - unbound affix +# Mapped to X as in the CoreNLP UniversalPOSMapper +AFX=POS_X +# GW - "goes with": part of a word that was split +GW=POS_X +# HYPH - hyphen +HYPH=POS_PUNCT +# NFP - superfluous punctuation, emoticons +NFP=POS_PUNCT +# XX - uninterpretable material, typos +XX=POS_X + +*=POS diff --git a/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/fr-ud2-pos.map b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/fr-ud2-pos.map new file mode 100644 index 0000000000..1fc4fdce6f --- /dev/null +++ b/dkpro-core-api-lexmorph-asl/src/main/resources/org/dkpro/core/api/lexmorph/tagset/fr-ud2-pos.map @@ -0,0 +1,23 @@ +# Universal Dependencies v2 POS tags + +__META_SOURCE_URL__=https://universaldependencies.org/u/pos/index.html +__META_TYPE_BASE__=de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos. + +*=POS +ADJ=POS_ADJ +ADP=POS_ADP +ADV=POS_ADV +AUX=POS_AUX +CCONJ=POS_CONJ +DET=POS_DET +INTJ=POS_INTJ +NOUN=POS_NOUN +NUM=POS_NUM +PART=POS_PART +PRON=POS_PRON +PROPN=POS_PROPN +PUNCT=POS_PUNCT +SCONJ=POS_SCONJ +SYM=POS_SYM +VERB=POS_VERB +X=POS_X diff --git a/dkpro-core-api-resources-asl/src/main/java/org/dkpro/core/api/resources/MappingProvider.java b/dkpro-core-api-resources-asl/src/main/java/org/dkpro/core/api/resources/MappingProvider.java index 372ddae947..485cc880af 100644 --- a/dkpro-core-api-resources-asl/src/main/java/org/dkpro/core/api/resources/MappingProvider.java +++ b/dkpro-core-api-resources-asl/src/main/java/org/dkpro/core/api/resources/MappingProvider.java @@ -182,6 +182,24 @@ public String getTagTypeName(String aTag) return type; } + /** + * Checks whether there is an explicit mapping for the given tag, i.e. whether the tag would be + * mapped without resorting to the fallback ({@code *}) mapping. + * + * @param aTag + * a tag. + * @return whether the tag is explicitly mapped. If no mapping could be loaded, this is always + * {@code false}. + */ + public boolean isExplicitlyMapped(String aTag) + { + if (notFound || getResource() == null) { + return false; + } + + return getResource().containsKey(getTag(aTag)); + } + public Set getTags() { return MappingUtils.stripMetadata(getResource().keySet()); diff --git a/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/de-ud2-dependency.map b/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/de-ud2-dependency.map new file mode 100644 index 0000000000..45feda7c6c --- /dev/null +++ b/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/de-ud2-dependency.map @@ -0,0 +1,103 @@ +# Universal Dependencies v2 + +__META_SOURCE_URL__=https://universaldependencies.org/u/dep/index.html +__META_TYPE_BASE__=de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency. + +# acl: clausal modifier of noun (adnominal clause) +acl=Dependency +# advcl: adverbial clause modifier +advcl=ADVCL +# advmod: adverbial modifier +advmod=ADVMOD +# amod: adjectival modifier +amod=AMOD +# appos: appositional modifier +appos=APPOS +# aux: auxiliary +aux=AUX0 +# case: case marking +case=PREP +# cc: coordinating conjunction +cc=CC +# ccomp: clausal complement +ccomp=CCOMP +# clf: classifier +clf=Dependency +# compound: compound +compound=NN +# conj: conjunct +conj=CONJ +# cop: copula +cop=COP +# csubj: clausal subject +csubj=CSUBJ +# dep: unspecified dependency +dep=DEP +# det: determiner +det=DET +# discourse: discourse element +discourse=Dependency +# dislocated: dislocated elements +dislocated=Dependency +# expl: expletive +expl=EXPL +# fixed: fixed multiword expression +fixed=MWE +# flat: flat multiword expression +flat=Dependency +# goeswith: goes with +goeswith=Dependency +# iobj: indirect object +iobj=IOBJ +# list: list +list=Dependency +# mark: marker +mark=MARK +# nmod: nominal modifier +nmod=Dependency +# nsubj: nominal subject +nsubj=NSUBJ +# nummod: numeric modifier +nummod=Dependency +# obj: object +obj=DOBJ +# obl: oblique nominal +obl=Dependency +# orphan: orphan +orphan=Dependency +# parataxis: parataxis +parataxis=PARATAXIS +# punct: punctuation +punct=PUNCT +# reparandum: overridden disfluency +reparandum=Dependency +# root: root +root=ROOT +# vocative: vocative +vocative=Dependency +# xcomp: open clausal complement +xcomp=XCOMP + +# Subtypes used by the German UD treebanks. +# Subtypes not listed here are mapped like their base relation (e.g. obl:arg like obl). +# acl:relcl: relative clause modifier +acl\:relcl=RCMOD +# aux:pass: passive auxiliary +aux\:pass=AUXPASS +# compound:prt: separable verb prefix +compound\:prt=PRT +# csubj:pass: clausal passive subject +csubj\:pass=CSUBJPASS +# det:poss: possessive determiner +det\:poss=POSS +# nmod:poss: possessive nominal modifier +nmod\:poss=POSS +# nsubj:pass: passive nominal subject +nsubj\:pass=NSUBJPASS +# obl:agent: agent in passive +obl\:agent=AGENT +# obl:tmod: temporal modifier +obl\:tmod=TMOD + +# Catch-all mapping +*=Dependency diff --git a/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/en-ud2-dependency.map b/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/en-ud2-dependency.map new file mode 100644 index 0000000000..7a9b1a3589 --- /dev/null +++ b/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/en-ud2-dependency.map @@ -0,0 +1,111 @@ +# Universal Dependencies v2 + +__META_SOURCE_URL__=https://universaldependencies.org/u/dep/index.html +__META_TYPE_BASE__=de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency. + +# acl: clausal modifier of noun (adnominal clause) +acl=Dependency +# advcl: adverbial clause modifier +advcl=ADVCL +# advmod: adverbial modifier +advmod=ADVMOD +# amod: adjectival modifier +amod=AMOD +# appos: appositional modifier +appos=APPOS +# aux: auxiliary +aux=AUX0 +# case: case marking +case=PREP +# cc: coordinating conjunction +cc=CC +# ccomp: clausal complement +ccomp=CCOMP +# clf: classifier +clf=Dependency +# compound: compound +compound=NN +# conj: conjunct +conj=CONJ +# cop: copula +cop=COP +# csubj: clausal subject +csubj=CSUBJ +# dep: unspecified dependency +dep=DEP +# det: determiner +det=DET +# discourse: discourse element +discourse=Dependency +# dislocated: dislocated elements +dislocated=Dependency +# expl: expletive +expl=EXPL +# fixed: fixed multiword expression +fixed=MWE +# flat: flat multiword expression +flat=Dependency +# goeswith: goes with +goeswith=Dependency +# iobj: indirect object +iobj=IOBJ +# list: list +list=Dependency +# mark: marker +mark=MARK +# nmod: nominal modifier +nmod=Dependency +# nsubj: nominal subject +nsubj=NSUBJ +# nummod: numeric modifier +nummod=Dependency +# obj: object +obj=DOBJ +# obl: oblique nominal +obl=Dependency +# orphan: orphan +orphan=Dependency +# parataxis: parataxis +parataxis=PARATAXIS +# punct: punctuation +punct=PUNCT +# reparandum: overridden disfluency +reparandum=Dependency +# root: root +root=ROOT +# vocative: vocative +vocative=Dependency +# xcomp: open clausal complement +xcomp=XCOMP + +# Subtypes used by the English UD treebanks. +# Subtypes not listed here are mapped like their base relation (e.g. obl:arg like obl). +# acl:relcl: relative clause modifier +acl\:relcl=RCMOD +# aux:pass: passive auxiliary +aux\:pass=AUXPASS +# cc:preconj: preconjunct +cc\:preconj=PRECONJ +# compound:prt: phrasal verb particle +compound\:prt=PRT +# csubj:pass: clausal passive subject +csubj\:pass=CSUBJPASS +# det:predet: predeterminer +det\:predet=PREDET +# nmod:npmod: noun phrase as adverbial modifier +nmod\:npmod=NPADVMOD +# nmod:poss: possessive nominal modifier +nmod\:poss=POSS +# nmod:tmod: temporal modifier +nmod\:tmod=TMOD +# nsubj:pass: passive nominal subject +nsubj\:pass=NSUBJPASS +# obl:agent: agent in passive +obl\:agent=AGENT +# obl:npmod: noun phrase as adverbial modifier +obl\:npmod=NPADVMOD +# obl:tmod: temporal modifier +obl\:tmod=TMOD + +# Catch-all mapping +*=Dependency diff --git a/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/fr-ud2-dependency.map b/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/fr-ud2-dependency.map new file mode 100644 index 0000000000..2377fda473 --- /dev/null +++ b/dkpro-core-api-syntax-asl/src/main/resources/org/dkpro/core/api/syntax/tagset/fr-ud2-dependency.map @@ -0,0 +1,95 @@ +# Universal Dependencies v2 + +__META_SOURCE_URL__=https://universaldependencies.org/u/dep/index.html +__META_TYPE_BASE__=de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency. + +# acl: clausal modifier of noun (adnominal clause) +acl=Dependency +# advcl: adverbial clause modifier +advcl=ADVCL +# advmod: adverbial modifier +advmod=ADVMOD +# amod: adjectival modifier +amod=AMOD +# appos: appositional modifier +appos=APPOS +# aux: auxiliary +aux=AUX0 +# case: case marking +case=PREP +# cc: coordinating conjunction +cc=CC +# ccomp: clausal complement +ccomp=CCOMP +# clf: classifier +clf=Dependency +# compound: compound +compound=NN +# conj: conjunct +conj=CONJ +# cop: copula +cop=COP +# csubj: clausal subject +csubj=CSUBJ +# dep: unspecified dependency +dep=DEP +# det: determiner +det=DET +# discourse: discourse element +discourse=Dependency +# dislocated: dislocated elements +dislocated=Dependency +# expl: expletive +expl=EXPL +# fixed: fixed multiword expression +fixed=MWE +# flat: flat multiword expression +flat=Dependency +# goeswith: goes with +goeswith=Dependency +# iobj: indirect object +iobj=IOBJ +# list: list +list=Dependency +# mark: marker +mark=MARK +# nmod: nominal modifier +nmod=Dependency +# nsubj: nominal subject +nsubj=NSUBJ +# nummod: numeric modifier +nummod=Dependency +# obj: object +obj=DOBJ +# obl: oblique nominal +obl=Dependency +# orphan: orphan +orphan=Dependency +# parataxis: parataxis +parataxis=PARATAXIS +# punct: punctuation +punct=PUNCT +# reparandum: overridden disfluency +reparandum=Dependency +# root: root +root=ROOT +# vocative: vocative +vocative=Dependency +# xcomp: open clausal complement +xcomp=XCOMP + +# Subtypes used by the French UD treebanks. +# Subtypes not listed here are mapped like their base relation (e.g. obl:arg like obl). +# acl:relcl: relative clause modifier +acl\:relcl=RCMOD +# aux:pass: passive auxiliary +aux\:pass=AUXPASS +# csubj:pass: clausal passive subject +csubj\:pass=CSUBJPASS +# nsubj:pass: passive nominal subject +nsubj\:pass=NSUBJPASS +# obl:agent: agent in passive +obl\:agent=AGENT + +# Catch-all mapping +*=Dependency diff --git a/dkpro-core-corenlp-gpl/pom.xml b/dkpro-core-corenlp-gpl/pom.xml index 92361ae39b..5ce3727d0d 100644 --- a/dkpro-core-corenlp-gpl/pom.xml +++ b/dkpro-core-corenlp-gpl/pom.xml @@ -190,7 +190,7 @@ de.tudarmstadt.ukp.dkpro.core - de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-bidirectional-distsim + de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-left3words-distsim test @@ -198,6 +198,11 @@ de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-fast test + + de.tudarmstadt.ukp.dkpro.core + de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-ud + test + de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-sd @@ -369,7 +374,12 @@ de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-ud - 20161213.1 + 20241017.0 + + + de.tudarmstadt.ukp.dkpro.core + de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-fr-ud + 20200420.0 de.tudarmstadt.ukp.dkpro.core @@ -394,7 +404,7 @@ de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-left3words-distsim - 20181002.1 + 20201103.0 de.tudarmstadt.ukp.dkpro.core @@ -544,32 +554,22 @@ de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-de-ud - 20161213.1 + 20241017.0 de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-sd - 20150418.1 + 20201106.0 de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-ud - 20161213.1 - - - de.tudarmstadt.ukp.dkpro.core - de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-wsj-sd - 20150418.1 - - - de.tudarmstadt.ukp.dkpro.core - de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-wsj-ud - 20161213.1 + 20201106.0 de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-fr-ud - 20180227.1 + 20200420.0 de.tudarmstadt.ukp.dkpro.core @@ -605,8 +605,9 @@ de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-coref-en-default de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-ner-en-all.3class.distsim.crf de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-parser-en-factored - de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-bidirectional-distsim + de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-left3words-distsim de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-fast + de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-ud de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-sd @@ -713,6 +714,16 @@ de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-ud test + + de.tudarmstadt.ukp.dkpro.core + de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-left3words-distsim + test + + + de.tudarmstadt.ukp.dkpro.core + de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-fr-ud + test + de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-fast-caseless @@ -863,16 +874,6 @@ de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-ud test - - de.tudarmstadt.ukp.dkpro.core - de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-wsj-sd - test - - - de.tudarmstadt.ukp.dkpro.core - de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-wsj-ud - test - de.tudarmstadt.ukp.dkpro.core de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-fr-ud @@ -912,8 +913,6 @@ de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-de-ud de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-ptb-conll de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-ud - de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-wsj-sd - de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-en-wsj-ud de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-fr-ud de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-zh-ctb-conll de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.corenlp-model-depparser-zh-ptb-conll @@ -953,6 +952,8 @@ de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-parser-zh-xinhua-factored de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-ar-default de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-ud + de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-left3words-distsim + de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-fr-ud de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-fast-caseless de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-de-hgc de.tudarmstadt.ukp.dkpro.core:de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-tagger-en-caseless-left3words-distsim diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpDependencyParser.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpDependencyParser.java index c05c4425d9..8166c53a18 100644 --- a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpDependencyParser.java +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpDependencyParser.java @@ -20,6 +20,7 @@ package org.dkpro.core.corenlp; import static org.apache.uima.util.Level.INFO; +import static org.apache.uima.util.Level.WARNING; import java.io.IOException; import java.net.URL; @@ -44,6 +45,7 @@ import org.dkpro.core.api.resources.ModelProviderBase; import org.dkpro.core.corenlp.internal.CoreNlp2DKPro; import org.dkpro.core.corenlp.internal.DKPro2CoreNlp; +import org.dkpro.core.corenlp.internal.PosTagsetCompatibilityChecker; import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS; import de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency; @@ -158,13 +160,16 @@ public class CoreNlpDependencyParser private int maxTime; /** - * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). + * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). If not set, the setting is + * taken from the model metadata ({@code ptb3Escaping}). Models which do not declare it (models + * trained for CoreNLP 3.x and earlier) use escaping. Models for CoreNLP 4.x expect unescaped + * tokens. * * @see PTBEscapingProcessor */ public static final String PARAM_PTB3_ESCAPING = "ptb3Escaping"; - @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, defaultValue = "true") - private boolean ptb3Escaping; + @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, mandatory = false) + private Boolean ptb3Escaping; /** * List of extra token texts (usually single character strings) that should be treated like @@ -190,6 +195,7 @@ public class CoreNlpDependencyParser GrammaticalStructure.Extras extraDependencies; private CasConfigurableProviderBase annotatorProvider; + private PosTagsetCompatibilityChecker posTagsetChecker; private MappingProvider mappingProvider; @Override @@ -199,6 +205,8 @@ public void initialize(UimaContext aContext) throws ResourceInitializationExcept annotatorProvider = new CoreNlpDependencyParserModelProvider(this); + posTagsetChecker = new PosTagsetCompatibilityChecker(); + mappingProvider = MappingProviderFactory.createDependencyMappingProvider(this, dependencyMappingLocation, language, annotatorProvider); @@ -213,9 +221,17 @@ public void process(JCas aJCas) throws AnalysisEngineProcessException annotatorProvider.configure(cas); mappingProvider.configure(cas); + // Warn if the POS tags in the CAS do not match the tagset expected by the model + String posTagsetWarning = posTagsetChecker.check(aJCas, annotatorProvider.getResource(), + annotatorProvider.getResourceMetaData()); + if (posTagsetWarning != null) { + getContext().getLogger().log(WARNING, posTagsetWarning); + } + // Transfer from CAS to CoreNLP DKPro2CoreNlp converter = new DKPro2CoreNlp(); - converter.setPtb3Escaping(ptb3Escaping); + converter.setPtb3Escaping(DKPro2CoreNlp.resolvePtb3Escaping(ptb3Escaping, + annotatorProvider.getResourceMetaData())); converter.setQuoteBegin(quoteBegin); converter.setQuoteEnd(quoteEnd); converter.setEncoding(modelEncoding); @@ -283,6 +299,8 @@ protected DependencyParseAnnotator produceResource(URL aUrl) throws IOException posTags.remove("-ROOT-"); posTags.remove("-UNKNOWN-"); addTagset(posTags, false); + posTagsetChecker.registerModel(annotator, + posTags.listTags(posTags.getLayer(), posTags.getTagset())); SingletonTagset depTags = new SingletonTagset(Dependency.class, metadata.getProperty(("dependency.tagset"))); diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpLemmatizer.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpLemmatizer.java index 6eda4853bb..eae628a3d8 100644 --- a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpLemmatizer.java +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpLemmatizer.java @@ -59,12 +59,14 @@ public class CoreNlpLemmatizer extends JCasAnnotator_ImplBase { /** - * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). + * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). Disabled by default to + * match the CoreNLP 4.x models which expect unescaped tokens. If enabled, e.g. brackets are + * lemmatized as {@code -lrb-} and {@code -rrb-}. * * @see PTBEscapingProcessor */ public static final String PARAM_PTB3_ESCAPING = "ptb3Escaping"; - @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, mandatory = true, defaultValue = "true") + @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, mandatory = true, defaultValue = "false") private boolean ptb3Escaping; /** diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpNamedEntityRecognizer.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpNamedEntityRecognizer.java index bcbe52db0f..1f1adcc2c9 100644 --- a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpNamedEntityRecognizer.java +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpNamedEntityRecognizer.java @@ -152,13 +152,16 @@ public class CoreNlpNamedEntityRecognizer private int numThreads; /** - * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). + * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). If not set, the setting is + * taken from the model metadata ({@code ptb3Escaping}). Models which do not declare it (models + * trained for CoreNLP 3.x and earlier) use escaping. Models for CoreNLP 4.x expect unescaped + * tokens. * * @see PTBEscapingProcessor */ public static final String PARAM_PTB3_ESCAPING = "ptb3Escaping"; - @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, defaultValue = "true") - private boolean ptb3Escaping; + @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, mandatory = false) + private Boolean ptb3Escaping; /** * List of extra token texts (usually single character strings) that should be treated like @@ -220,7 +223,8 @@ public void process(JCas aJCas) throws AnalysisEngineProcessException // Transfer from CAS to CoreNLP DKPro2CoreNlp converter = new DKPro2CoreNlp(); - converter.setPtb3Escaping(ptb3Escaping); + converter.setPtb3Escaping(DKPro2CoreNlp.resolvePtb3Escaping(ptb3Escaping, + annotatorProvider.getResourceMetaData())); converter.setQuoteBegin(quoteBegin); converter.setQuoteEnd(quoteEnd); converter.setEncoding(modelEncoding); diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpParser.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpParser.java index 7bccc0bd49..86c0b1e457 100644 --- a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpParser.java +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpParser.java @@ -47,6 +47,7 @@ import org.dkpro.core.api.resources.ModelProviderBase; import org.dkpro.core.corenlp.internal.CoreNlp2DKPro; import org.dkpro.core.corenlp.internal.DKPro2CoreNlp; +import org.dkpro.core.corenlp.internal.PosTagsetCompatibilityChecker; import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS; import de.tudarmstadt.ukp.dkpro.core.api.syntax.type.constituent.Constituent; @@ -69,6 +70,9 @@ import edu.stanford.nlp.trees.UniversalEnglishGrammaticalRelations; import edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructureFactory; import edu.stanford.nlp.trees.international.pennchinese.ChineseGrammaticalRelations; +import edu.stanford.nlp.trees.international.pennchinese.ChineseGrammaticalStructureFactory; +import edu.stanford.nlp.trees.international.pennchinese.UniversalChineseGrammaticalRelations; +import edu.stanford.nlp.trees.international.pennchinese.UniversalChineseGrammaticalStructureFactory; import eu.openminted.share.annotations.api.Component; import eu.openminted.share.annotations.api.DocumentationResource; import eu.openminted.share.annotations.api.constants.OperationType; @@ -190,13 +194,16 @@ public class CoreNlpParser private int maxTime; /** - * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). + * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). If not set, the setting is + * taken from the model metadata ({@code ptb3Escaping}). Models which do not declare it (models + * trained for CoreNLP 3.x and earlier) use escaping. Models for CoreNLP 4.x expect unescaped + * tokens. * * @see PTBEscapingProcessor */ public static final String PARAM_PTB3_ESCAPING = "ptb3Escaping"; - @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, defaultValue = "true") - private boolean ptb3Escaping; + @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, mandatory = false) + private Boolean ptb3Escaping; /** * List of extra token texts (usually single character strings) that should be treated like @@ -260,11 +267,13 @@ public class CoreNlpParser private boolean writeDependency; /** - * Generate original Stanford Dependencies grammatical relations instead of Universal - * Dependencies. + * Generate original Stanford Dependencies grammatical relations ({@code stanford341} tagset) + * instead of Universal Dependencies. Only affects languages for which CoreNLP converts + * constituency trees to dependencies: English (Universal Dependencies v2, {@code ud2} tagset) + * and Chinese (Universal Dependencies v1, {@code universal} tagset). */ public static final String PARAM_ORIGINAL_DEPENDENCIES = "originalDependencies"; - @ConfigurationParameter(name = PARAM_ORIGINAL_DEPENDENCIES, defaultValue = "true") + @ConfigurationParameter(name = PARAM_ORIGINAL_DEPENDENCIES, defaultValue = "false") private boolean originalDependencies; /** @@ -275,6 +284,7 @@ public class CoreNlpParser private boolean keepPunctuation; private CasConfigurableProviderBase annotatorProvider; + private PosTagsetCompatibilityChecker posTagsetChecker; private MappingProvider dependencyMappingProvider; private MappingProvider constituentMappingProvider; private MappingProvider posMappingProvider; @@ -286,6 +296,8 @@ public void initialize(UimaContext aContext) throws ResourceInitializationExcept annotatorProvider = new CoreNlpParserModelProvider(this); + posTagsetChecker = new PosTagsetCompatibilityChecker(); + constituentMappingProvider = createConstituentMappingProvider(this, constituentMappingLocation, language, annotatorProvider); @@ -305,9 +317,19 @@ public void process(JCas aJCas) throws AnalysisEngineProcessException annotatorProvider.configure(cas); + if (readPos) { + // Warn if the POS tags in the CAS do not match the tagset expected by the model + String posTagsetWarning = posTagsetChecker.check(aJCas, annotatorProvider.getResource(), + annotatorProvider.getResourceMetaData()); + if (posTagsetWarning != null) { + getContext().getLogger().log(WARNING, posTagsetWarning); + } + } + // Transfer from CAS to CoreNLP DKPro2CoreNlp converter = new DKPro2CoreNlp(); - converter.setPtb3Escaping(ptb3Escaping); + converter.setPtb3Escaping(DKPro2CoreNlp.resolvePtb3Escaping(ptb3Escaping, + annotatorProvider.getResourceMetaData())); converter.setQuoteBegin(quoteBegin); converter.setQuoteEnd(quoteEnd); converter.setEncoding(modelEncoding); @@ -430,6 +452,8 @@ protected ParserAnnotator produceResource(URL aUrl) throws IOException } posTags.remove(Lexicon.BOUNDARY_TAG); addTagset(posTags, writePos); + posTagsetChecker.registerModel(annotator, + posTags.listTags(posTags.getLayer(), posTags.getTagset())); } // https://mailman.stanford.edu/pipermail/parser-user/2012-November/002117.html @@ -505,6 +529,10 @@ else if (parser instanceof ShiftReduceParser) { // https://mailman.stanford.edu/pipermail/java-nlp-user/2016-January/007417.html // https://mailman.stanford.edu/pipermail/java-nlp-user/2013-December/004429.html if (gsf != null && EnglishGrammaticalStructureFactory.class.equals(gsf.getClass())) { + // The dependency mapping is selected via the model metadata + if (metadata.getProperty("dependency.tagset") == null) { + metadata.setProperty("dependency.tagset", "stanford341"); + } SingletonTagset depTags = new SingletonTagset(Dependency.class, "stanford341"); for (GrammaticalRelation r : EnglishGrammaticalRelations.values()) { depTags.add(r.getShortName()); @@ -515,7 +543,12 @@ else if (parser instanceof ShiftReduceParser) { } else if (gsf != null && UniversalEnglishGrammaticalStructureFactory.class.equals(gsf.getClass())) { - SingletonTagset depTags = new SingletonTagset(Dependency.class, "universal"); + // CoreNLP 4.x produces Universal Dependencies v2. The dependency mapping is + // selected via the model metadata + if (metadata.getProperty("dependency.tagset") == null) { + metadata.setProperty("dependency.tagset", "ud2"); + } + SingletonTagset depTags = new SingletonTagset(Dependency.class, "ud2"); for (GrammaticalRelation r : UniversalEnglishGrammaticalRelations.values()) { depTags.add(r.getShortName()); } @@ -523,8 +556,13 @@ else if (gsf != null addTagset(depTags, writeDependency); } } - else if (gsf != null && ChineseGrammaticalRelations.class.equals(gsf.getClass())) { - SingletonTagset depTags = new SingletonTagset(Dependency.class, "stanford"); + else if (gsf != null + && ChineseGrammaticalStructureFactory.class.equals(gsf.getClass())) { + // The dependency mapping is selected via the model metadata + if (metadata.getProperty("dependency.tagset") == null) { + metadata.setProperty("dependency.tagset", "stanford341"); + } + SingletonTagset depTags = new SingletonTagset(Dependency.class, "stanford341"); for (GrammaticalRelation r : ChineseGrammaticalRelations.values()) { depTags.add(r.getShortName()); } @@ -532,6 +570,21 @@ else if (gsf != null && ChineseGrammaticalRelations.class.equals(gsf.getClass()) addTagset(depTags, writeDependency); } } + else if (gsf != null + && UniversalChineseGrammaticalStructureFactory.class.equals(gsf.getClass())) { + // CoreNLP produces Universal Dependencies v1 for Chinese. The dependency mapping + // is selected via the model metadata + if (metadata.getProperty("dependency.tagset") == null) { + metadata.setProperty("dependency.tagset", "universal"); + } + SingletonTagset depTags = new SingletonTagset(Dependency.class, "universal"); + for (GrammaticalRelation r : UniversalChineseGrammaticalRelations.values()) { + depTags.add(r.getShortName()); + } + if (writeDependency) { + addTagset(depTags, writeDependency); + } + } if (printTagSet) { getContext().getLogger().log(INFO, getTagset().toString()); diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpPosTagger.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpPosTagger.java index 74dc5e9773..f64a932ccc 100644 --- a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpPosTagger.java +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/CoreNlpPosTagger.java @@ -147,13 +147,16 @@ public class CoreNlpPosTagger private int numThreads; /** - * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). + * Enable all traditional PTB3 token transforms (like -LRB-, -RRB-). If not set, the setting is + * taken from the model metadata ({@code ptb3Escaping}). Models which do not declare it (models + * trained for CoreNLP 3.x and earlier) use escaping. Models for CoreNLP 4.x expect unescaped + * tokens. * * @see PTBEscapingProcessor */ public static final String PARAM_PTB3_ESCAPING = "ptb3Escaping"; - @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, defaultValue = "true") - private boolean ptb3Escaping; + @ConfigurationParameter(name = PARAM_PTB3_ESCAPING, mandatory = false) + private Boolean ptb3Escaping; /** * List of extra token texts (usually single character strings) that should be treated like @@ -197,7 +200,8 @@ public void process(JCas aJCas) throws AnalysisEngineProcessException // Transfer from CAS to CoreNLP DKPro2CoreNlp converter = new DKPro2CoreNlp(); - converter.setPtb3Escaping(ptb3Escaping); + converter.setPtb3Escaping(DKPro2CoreNlp.resolvePtb3Escaping(ptb3Escaping, + annotatorProvider.getResourceMetaData())); converter.setQuoteBegin(quoteBegin); converter.setQuoteEnd(quoteEnd); converter.setEncoding(modelEncoding); diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/CoreNlp2DKPro.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/CoreNlp2DKPro.java index e7ec9672b4..c6c46f85f5 100644 --- a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/CoreNlp2DKPro.java +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/CoreNlp2DKPro.java @@ -154,9 +154,13 @@ public static void convertDependencies(JCas aJCas, Annotation document, String labelUsedForMapping = edge.getRelation().getShortName(); // The nndepparser may produce labels in which the shortName contains a colon. - // These represent language-specific labels of the UD, cf: - // http://universaldependencies.github.io/docs/ext-dep-index.html - labelUsedForMapping = StringUtils.substringBefore(labelUsedForMapping, ":"); + // These represent subtypes of the UD relations (e.g. nsubj:pass), cf: + // https://universaldependencies.org/u/dep/index.html + // If the mapping has an entry for the full subtype, we use that. Otherwise, we + // fall back to the base relation. + if (!mappingProvider.isExplicitlyMapped(labelUsedForMapping)) { + labelUsedForMapping = StringUtils.substringBefore(labelUsedForMapping, ":"); + } // Need to use toString() here to get "_" String actualLabel = edge.getRelation().toString(); diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/DKPro2CoreNlp.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/DKPro2CoreNlp.java index 0422a2df76..7e891123ee 100644 --- a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/DKPro2CoreNlp.java +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/DKPro2CoreNlp.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import org.apache.commons.lang3.StringUtils; import org.apache.uima.cas.CASException; @@ -79,6 +80,12 @@ public class DKPro2CoreNlp { + /** + * Model metadata key declaring whether a model expects PTB3-escaped tokens (e.g. {@code -LRB-} + * instead of {@code (}). + */ + public static final String META_PTB3_ESCAPING = "ptb3Escaping"; + private CoreLabelTokenFactory tokenFactory = new CoreLabelTokenFactory(); private boolean ptb3Escaping; @@ -117,6 +124,35 @@ public void setPtb3Escaping(boolean aPtb3Escaping) ptb3Escaping = aPtb3Escaping; } + /** + * Determines whether PTB3 escaping should be applied. An explicitly configured value takes + * precedence. Otherwise, the value declared in the model metadata under + * {@link #META_PTB3_ESCAPING} is used. If the model does not declare it, escaping is enabled + * because that is what models trained for CoreNLP 3.x and earlier expect. Models for CoreNLP + * 4.x expect unescaped tokens and declare {@code ptb3Escaping=false}. + * + * @param aConfiguredValue + * the value configured on the component or {@code null} if not configured. + * @param aModelMetadata + * the metadata of the model or {@code null} if not available. + * @return whether PTB3 escaping should be applied. + */ + public static boolean resolvePtb3Escaping(Boolean aConfiguredValue, Properties aModelMetadata) + { + if (aConfiguredValue != null) { + return aConfiguredValue; + } + + if (aModelMetadata != null) { + String value = aModelMetadata.getProperty(META_PTB3_ESCAPING); + if (value != null) { + return Boolean.parseBoolean(value); + } + } + + return true; + } + public List getQuoteBegin() { return quoteBegin; diff --git a/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/PosTagsetCompatibilityChecker.java b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/PosTagsetCompatibilityChecker.java new file mode 100644 index 0000000000..05db409f7b --- /dev/null +++ b/dkpro-core-corenlp-gpl/src/main/java/org/dkpro/core/corenlp/internal/PosTagsetCompatibilityChecker.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Technische Universität Darmstadt under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. + * + * This program 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. + * + * This program 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.dkpro.core.corenlp.internal; + +import static org.apache.uima.fit.util.JCasUtil.select; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; +import java.util.WeakHashMap; +import java.util.stream.Collectors; + +import org.apache.uima.jcas.JCas; + +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token; + +/** + * Detects when the POS tags in the CAS do not match the POS tagset expected by a parser model, e.g. + * when a POS tagger producing STTS tags is combined with a dependency parser trained on Universal + * Dependencies POS tags. Parsers do not fail in such a case but silently produce poor results. + */ +public class PosTagsetCompatibilityChecker +{ + /** + * Share of POS-tagged tokens carrying a tag unknown to the model above which the tagsets are + * considered incompatible. Individual unknown tags are normal (e.g. rare tags missing from the + * training data) and are not reported. + */ + public static final double INCOMPATIBILITY_THRESHOLD = 0.5; + + private static final int MAX_REPORTED_TAGS = 10; + + private final Map> knownTagsByModel = Collections + .synchronizedMap(new WeakHashMap<>()); + + private final Set reportedModels = Collections + .newSetFromMap(Collections.synchronizedMap(new WeakHashMap<>())); + + /** + * Registers the POS tags known to a model. + * + * @param aModel + * the loaded model (used as key, held weakly). + * @param aKnownTags + * the POS tags known to the model. + */ + public void registerModel(Object aModel, Set aKnownTags) + { + knownTagsByModel.put(aModel, new HashSet<>(aKnownTags)); + } + + /** + * Checks the POS tags in the CAS against the tags known to the given model. + * + * @param aJCas + * the CAS. + * @param aModel + * the model which is about to process the CAS. + * @param aModelMetadata + * the metadata of the model. + * @return a warning message if the POS tags in the CAS appear incompatible with the model and + * no warning has been issued for this model yet, otherwise {@code null}. + */ + public String check(JCas aJCas, Object aModel, Properties aModelMetadata) + { + Set knownTags = knownTagsByModel.get(aModel); + if (knownTags == null || knownTags.isEmpty() || reportedModels.contains(aModel)) { + return null; + } + + int tagged = 0; + int unknown = 0; + Set unknownTags = new TreeSet<>(); + for (Token token : select(aJCas, Token.class)) { + String tag = token.getPosValue(); + if (tag == null) { + continue; + } + + tagged++; + if (!knownTags.contains(tag)) { + unknown++; + unknownTags.add(tag); + } + } + + if (tagged == 0 || (double) unknown / tagged <= INCOMPATIBILITY_THRESHOLD) { + return null; + } + + reportedModels.add(aModel); + + String modelTagset = aModelMetadata != null + ? aModelMetadata.getProperty("pos.tagset", "unknown") + : "unknown"; + String modelName = aModelMetadata != null + ? aModelMetadata.getProperty("language", "?") + "/" + + aModelMetadata.getProperty("variant", "?") + : "?"; + String sample = unknownTags.stream().limit(MAX_REPORTED_TAGS) + .collect(Collectors.joining(", ")); + + return String.format( + "%d of %d POS tags in the input are unknown to the model [%s] which expects the " + + "POS tagset [%s] (e.g. %s). The POS tagger and the parser model appear " + + "to use incompatible tagsets, which degrades the parse quality. Use a " + + "POS tagger model producing the [%s] tagset.", + unknown, tagged, modelName, modelTagset, sample, modelTagset); + } +} diff --git a/dkpro-core-corenlp-gpl/src/main/resources/org/dkpro/core/corenlp/lib/tagger-default-variants.map b/dkpro-core-corenlp-gpl/src/main/resources/org/dkpro/core/corenlp/lib/tagger-default-variants.map index aa4c942157..fd35a67ea0 100644 --- a/dkpro-core-corenlp-gpl/src/main/resources/org/dkpro/core/corenlp/lib/tagger-default-variants.map +++ b/dkpro-core-corenlp-gpl/src/main/resources/org/dkpro/core/corenlp/lib/tagger-default-variants.map @@ -1,6 +1,6 @@ ar=default -de=fast -fr=default -en=bidirectional-distsim +de=ud +fr=ud +en=left3words-distsim es=distsim zh=distsim diff --git a/dkpro-core-corenlp-gpl/src/scripts/build.xml b/dkpro-core-corenlp-gpl/src/scripts/build.xml index 48bcd2984b..45d6856555 100644 --- a/dkpro-core-corenlp-gpl/src/scripts/build.xml +++ b/dkpro-core-corenlp-gpl/src/scripts/build.xml @@ -28,12 +28,17 @@ - Upstream versions - meta data versions are maintained per model below --> - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -74,18 +126,19 @@ - - + + + @@ -94,12 +147,65 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -108,76 +214,30 @@ - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -186,23 +246,27 @@ - + + + @@ -236,6 +300,9 @@ + @@ -262,6 +329,9 @@ + @@ -288,6 +358,9 @@ + @@ -315,9 +388,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -326,18 +445,19 @@ - - + + + @@ -348,6 +468,9 @@ + @@ -380,7 +503,7 @@ - @@ -391,7 +514,7 @@ - @@ -402,7 +525,7 @@ - @@ -413,29 +536,18 @@ - - - - - - - - - - - - diff --git a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpCoreferenceResolverTest.java b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpCoreferenceResolverTest.java index 66c971d81a..cc778d6449 100644 --- a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpCoreferenceResolverTest.java +++ b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpCoreferenceResolverTest.java @@ -64,12 +64,11 @@ public void testTriggerReparse() throws Exception { JCas jcas = runTest("en", "'Let's go! I want to see the Don', he said."); - String[][] ref = { { "Let" }, { "go" }, { "I" }, { "the Don'", "he" } }; + String[][] ref = { { "'s", "I" }, { "the Don", "he" } }; - String[] pennTree = { - "(ROOT (S ('' ') (NP (NNP Let)) (VP (S (VP (POS 's) (NP (VB go))))) (. !)))", + String[] pennTree = { "(ROOT (S (`` ') (VP (VB Let) (NP (PRP 's)) (VP (VB go))) (. !)))", "(ROOT (S (S (NP (PRP I)) (VP (VBP want) (S (VP (TO to) (VP (VB see) (NP (DT the) " - + "(NX (NNP Don) (POS ')))))))) (, ,) (NP (PRP he)) (VP (VBD said)) (. .)))" }; + + "(NNP Don)))) ('' ')))) (, ,) (NP (PRP he)) (VP (VBD said)) (. .)))" }; AssertAnnotations.assertCoreference(ref, select(jcas, CoreferenceChain.class)); AssertAnnotations.assertPennTree(pennTree, select(jcas, PennTree.class)); diff --git a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpDependencyParserTest.java b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpDependencyParserTest.java index bbec84181e..6bf96c229d 100644 --- a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpDependencyParserTest.java +++ b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpDependencyParserTest.java @@ -37,39 +37,30 @@ public class CoreNlpDependencyParserTest { - private static final String[] GERMAN_POS_TAGS = { "$,", "$.", "$[", "ADJA", "ADJD", "ADV", - "APPO", "APPR", "APPRART", "APZR", "ART", "CARD", "FM", "ITJ", "KOKOM", "KON", "KOUI", - "KOUS", "NE", "NN", "PDAT", "PDS", "PIAT", "PIDAT", "PIS", "PPER", "PPOSAT", "PPOSS", - "PRELAT", "PRELS", "PRF", "PROAV", "PTKA", "PTKANT", "PTKNEG", "PTKVZ", "PTKZU", "PWAT", - "PWAV", "PWS", "TRUNC", "VAFIN", "VAIMP", "VAINF", "VAPP", "VMFIN", "VMINF", "VMPP", - "VVFIN", "VVIMP", "VVINF", "VVIZU", "VVPP", "XY" }; private static final String[] STANFORD_DEPENDENCY_TAGS = { "acomp", "advcl", "advmod", "amod", "appos", "aux", "auxpass", "cc", "ccomp", "conj", "cop", "csubj", "csubjpass", "dep", - "det", "discourse", "dobj", "expl", "iobj", "mark", "mwe", "neg", "nn", "npadvmod", - "nsubj", "nsubjpass", "num", "number", "parataxis", "pcomp", "pobj", "poss", - "possessive", "preconj", "predet", "prep", "prt", "punct", "quantmod", "rcmod", "root", - "tmod", "vmod", "xcomp" }; - - private static final String[] UNIVERSAL_DEPENDENCY_TAGS = { "acl", "acl:relcl", "advcl", - "advmod", "amod", "appos", "aux", "auxpass", "case", "cc", "cc:preconj", "ccomp", - "compound", "compound:prt", "conj", "cop", "csubj", "csubjpass", "dep", "det", - "det:predet", "discourse", "dobj", "expl", "iobj", "list", "mark", "mwe", "neg", "nmod", - "nmod:npmod", "nmod:poss", "nmod:tmod", "nsubj", "nsubjpass", "nummod", "parataxis", + "det", "discourse", "dobj", "erased", "expl", "goeswith", "iobj", "mark", "mwe", "neg", + "nn", "npadvmod", "nsubj", "nsubjpass", "num", "number", "parataxis", "pcomp", "pobj", + "poss", "possessive", "preconj", "predet", "prep", "prt", "punct", "quantmod", "rcmod", + "root", "tmod", "vmod", "xcomp" }; + + private static final String[] UD2_DEPENDENCY_TAGS = { "acl", "acl:relcl", "advcl", "advmod", + "amod", "appos", "aux", "aux:pass", "case", "cc", "cc:preconj", "ccomp", "compound", + "compound:prt", "conj", "cop", "csubj", "csubj:pass", "dep", "det", "det:predet", + "discourse", "expl", "fixed", "goeswith", "iobj", "mark", "nmod", "nmod:poss", "nsubj", + "nsubj:pass", "nummod", "obj", "obl", "obl:npmod", "obl:tmod", "orphan", "parataxis", "punct", "root", "xcomp" }; - private static final String[] PTB_POS_TAGS = { "#", "$", "''", ",", "-LRB-", "-RRB-", ".", ":", - "CC", "CD", "DT", "EX", "FW", "IN", "JJ", "JJR", "JJS", "LS", "MD", "NN", "NNP", "NNPS", - "NNS", "PDT", "POS", "PRP", "PRP$", "RB", "RBR", "RBS", "RP", "SYM", "TO", "UH", "VB", - "VBD", "VBG", "VBN", "VBP", "VBZ", "WDT", "WP", "WP$", "WRB", "``" }; + private static final String[] EWT_PTB_POS_TAGS = { "$", "''", ",", "-LRB-", "-RRB-", ".", ":", + "ADD", "AFX", "CC", "CD", "DT", "EX", "FW", "GW", "HYPH", "IN", "JJ", "JJR", "JJS", + "LS", "MD", "NFP", "NN", "NNP", "NNPS", "NNS", "PDT", "POS", "PRP", "PRP$", "RB", "RBR", + "RBS", "RP", "SYM", "TO", "UH", "VB", "VBD", "VBG", "VBN", "VBP", "VBZ", "WDT", "WP", + "WP$", "WRB", "``" }; - private static final String[] UNIVERSAL_POS_TAGS = { "ADJ", "ADP", "ADV", "AUX", "CONJ", "DET", + private static final String[] UD2_POS_TAGS = { "ADJ", "ADP", "ADV", "AUX", "CCONJ", "DET", "INTJ", "NOUN", "NUM", "PART", "PRON", "PROPN", "PUNCT", "SCONJ", "SYM", "VERB", "X" }; - private static final String[] CORENLP34_POS_TAGS = { "A", "ADJ", "ADJWH", "ADV", "ADVWH", "C", - "CC", "CL", "CLO", "CLR", "CLS", "CS", "DET", "DETWH", "ET", "I", "N", "NC", "NPP", "P", - "PREF", "PRO", "PROREL", "PROWH", "PUNC", "V", "VIMP", "VINF", "VPP", "VPR", "VS" }; - @Test public void testEnglishStanfordDependencies() throws Exception { @@ -80,7 +71,7 @@ public void testEnglishStanfordDependencies() throws Exception "[ 3, 7]ROOT(root,basic) D[3,7](need) G[3,7](need)", "[ 8, 9]DET(det,basic) D[8,9](a) G[35,43](sentence)", "[ 10, 14]ADVMOD(advmod,basic) D[10,14](very) G[15,26](complicated)", - "[ 15, 26]AMOD(amod,basic) D[15,26](complicated) G[35,43](sentence)", + "[ 15, 26]AMOD(amod,basic) D[15,26](complicated) G[27,34](example)", "[ 27, 34]NN(nn,basic) D[27,34](example) G[35,43](sentence)", "[ 35, 43]DOBJ(dobj,basic) D[35,43](sentence) G[3,7](need)", "[ 44, 45]PUNCT(punct,basic) D[44,45](,) G[35,43](sentence)", @@ -92,11 +83,11 @@ public void testEnglishStanfordDependencies() throws Exception "[102,110]PREP(prep_as,basic) D[102,110](possible) G[69,81](constituents)", "[111,112]PUNCT(punct,basic) D[111,112](.) G[3,7](need)" }; - String[] unmappedDep = {}; + String[] unmappedDep = { "erased" }; assertDependencies(dependencies, select(jcas, Dependency.class)); - assertTagset(CoreNlpPosTagger.class, POS.class, "ptb", PTB_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, POS.class, "ptb", PTB_POS_TAGS, jcas); + assertTagset(CoreNlpPosTagger.class, POS.class, "ptb-ewt", EWT_PTB_POS_TAGS, jcas); + assertTagset(CoreNlpDependencyParser.class, POS.class, "ptb-ewt", EWT_PTB_POS_TAGS, jcas); assertTagset(CoreNlpDependencyParser.class, Dependency.class, "stanford341", STANFORD_DEPENDENCY_TAGS, jcas); assertTagsetMapping(Dependency.class, "stanford341", unmappedDep, jcas); @@ -114,157 +105,100 @@ public void testEnglishUniversalDependencies() throws Exception "[ 10, 14]ADVMOD(advmod,basic) D[10,14](very) G[15,26](complicated)", "[ 15, 26]AMOD(amod,basic) D[15,26](complicated) G[35,43](sentence)", "[ 27, 34]NN(compound,basic) D[27,34](example) G[35,43](sentence)", - "[ 35, 43]DOBJ(dobj,basic) D[35,43](sentence) G[3,7](need)", + "[ 35, 43]DOBJ(obj,basic) D[35,43](sentence) G[3,7](need)", "[ 44, 45]PUNCT(punct,basic) D[44,45](,) G[35,43](sentence)", "[ 46, 51]NSUBJ(nsubj,basic) D[46,51](which) G[52,60](contains)", - "[ 52, 60]Dependency(acl:relcl,basic) D[52,60](contains) G[35,43](sentence)", - "[ 61, 63]DOBJ(dobj,basic) D[61,63](as) G[52,60](contains)", + "[ 52, 60]RCMOD(acl:relcl,basic) D[52,60](contains) G[35,43](sentence)", + "[ 61, 63]PREP(case,basic) D[61,63](as) G[69,81](constituents)", "[ 64, 68]AMOD(amod,basic) D[64,68](many) G[69,81](constituents)", - "[ 69, 81]DEP(dep,basic) D[69,81](constituents) G[61,63](as)", - "[ 82, 85]CC(cc,basic) D[82,85](and) G[69,81](constituents)", - "[ 86, 98]CONJ(conj,basic) D[86,98](dependencies) G[69,81](constituents)", + "[ 69, 81]Dependency(obl:as,basic) D[69,81](constituents) G[52,60](contains)", + "[ 82, 85]CC(cc,basic) D[82,85](and) G[86,98](dependencies)", + "[ 86, 98]CONJ(conj:and,basic) D[86,98](dependencies) G[69,81](constituents)", "[ 99,101]PREP(case,basic) D[99,101](as) G[102,110](possible)", - "[102,110]Dependency(acl,basic) D[102,110](possible) G[69,81](constituents)", - "[111,112]PUNCT(punct,basic) D[111,112](.) G[3,7](need)" }; - - String[] unmappedDep = { "acl:relcl", "cc:preconj", "compound:prt", "det:predet", - "nmod:npmod", "nmod:poss", "nmod:tmod" }; - - assertDependencies(dependencies, select(jcas, Dependency.class)); - assertTagset(CoreNlpPosTagger.class, POS.class, "ptb", PTB_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, POS.class, "ptb", PTB_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, Dependency.class, "universal", - UNIVERSAL_DEPENDENCY_TAGS, jcas); - assertTagsetMapping(Dependency.class, "universal", unmappedDep, jcas); - } - - @Test - public void testEnglishWsjSd() throws Exception - { - JCas jcas = runTest("en", "wsj-sd", "We need a very complicated example sentence , which " - + "contains as many constituents and dependencies as possible ."); - - String[] dependencies = { "[ 0, 2]NSUBJ(nsubj,basic) D[0,2](We) G[3,7](need)", - "[ 3, 7]ROOT(root,basic) D[3,7](need) G[3,7](need)", - "[ 8, 9]DET(det,basic) D[8,9](a) G[35,43](sentence)", - "[ 10, 14]ADVMOD(advmod,basic) D[10,14](very) G[15,26](complicated)", - "[ 15, 26]AMOD(amod,basic) D[15,26](complicated) G[35,43](sentence)", - "[ 27, 34]NN(nn,basic) D[27,34](example) G[35,43](sentence)", - "[ 35, 43]DOBJ(dobj,basic) D[35,43](sentence) G[3,7](need)", - "[ 44, 45]PUNCT(punct,basic) D[44,45](,) G[35,43](sentence)", - "[ 46, 51]NSUBJ(nsubj,basic) D[46,51](which) G[52,60](contains)", - "[ 52, 60]RCMOD(rcmod,basic) D[52,60](contains) G[35,43](sentence)", - "[ 61, 63]PREP(prep,basic) D[61,63](as) G[52,60](contains)", - "[ 64, 68]AMOD(amod,basic) D[64,68](many) G[69,81](constituents)", - "[ 69, 81]POBJ(pobj,basic) D[69,81](constituents) G[61,63](as)", - "[ 82, 85]CC(cc,basic) D[82,85](and) G[69,81](constituents)", - "[ 86, 98]CONJ(conj,basic) D[86,98](dependencies) G[69,81](constituents)", - "[ 99,101]PREP(prep,basic) D[99,101](as) G[69,81](constituents)", - "[102,110]POBJ(pobj,basic) D[102,110](possible) G[99,101](as)", + "[102,110]ADVCL(advcl,basic) D[102,110](possible) G[52,60](contains)", "[111,112]PUNCT(punct,basic) D[111,112](.) G[3,7](need)" }; String[] unmappedDep = {}; assertDependencies(dependencies, select(jcas, Dependency.class)); - assertTagset(CoreNlpPosTagger.class, POS.class, "ptb", PTB_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, POS.class, "ptb", PTB_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, Dependency.class, "stanford341", - STANFORD_DEPENDENCY_TAGS, jcas); - assertTagsetMapping(Dependency.class, "stanford341", unmappedDep, jcas); + assertTagset(CoreNlpPosTagger.class, POS.class, "ptb-ewt", EWT_PTB_POS_TAGS, jcas); + assertTagset(CoreNlpDependencyParser.class, POS.class, "ptb-ewt", EWT_PTB_POS_TAGS, jcas); + assertTagset(CoreNlpDependencyParser.class, Dependency.class, "ud2", UD2_DEPENDENCY_TAGS, + jcas); + assertTagsetMapping(Dependency.class, "ud2", unmappedDep, jcas); } @Test - public void testEnglishWsjUd() throws Exception + public void testEnglishUniversalDependenciesPassive() throws Exception { - JCas jcas = runTest("en", "wsj-ud", "We need a very complicated example sentence , which " - + "contains as many constituents and dependencies as possible ."); - - String[] dependencies = { "[ 0, 2]NSUBJ(nsubj,basic) D[0,2](We) G[3,7](need)", - "[ 3, 7]ROOT(root,basic) D[3,7](need) G[3,7](need)", - "[ 8, 9]DET(det,basic) D[8,9](a) G[35,43](sentence)", - "[ 10, 14]ADVMOD(advmod,basic) D[10,14](very) G[15,26](complicated)", - "[ 15, 26]AMOD(amod,basic) D[15,26](complicated) G[35,43](sentence)", - "[ 27, 34]NN(compound,basic) D[27,34](example) G[35,43](sentence)", - "[ 35, 43]DOBJ(dobj,basic) D[35,43](sentence) G[3,7](need)", - "[ 44, 45]PUNCT(punct,basic) D[44,45](,) G[35,43](sentence)", - "[ 46, 51]NSUBJ(nsubj,basic) D[46,51](which) G[52,60](contains)", - "[ 52, 60]Dependency(acl:relcl,basic) D[52,60](contains) G[35,43](sentence)", - "[ 61, 63]PREP(case,basic) D[61,63](as) G[69,81](constituents)", - "[ 64, 68]AMOD(amod,basic) D[64,68](many) G[69,81](constituents)", - "[ 69, 81]Dependency(nmod:as,basic) D[69,81](constituents) G[52,60](contains)", - "[ 82, 85]CC(cc,basic) D[82,85](and) G[69,81](constituents)", - "[ 86, 98]CONJ(conj,basic) D[86,98](dependencies) G[69,81](constituents)", - "[ 99,101]PREP(case,basic) D[99,101](as) G[102,110](possible)", - "[102,110]Dependency(acl,basic) D[102,110](possible) G[69,81](constituents)", - "[111,112]PUNCT(punct,basic) D[111,112](.) G[3,7](need)" }; + JCas jcas = runTest("en", "ud", "The ball was kicked by John ."); - String[] depTags = { "acl", "acl:relcl", "advcl", "advmod", "amod", "appos", "aux", - "auxpass", "case", "cc", "cc:preconj", "ccomp", "compound", "compound:prt", "conj", - "cop", "csubj", "csubjpass", "dep", "det", "det:predet", "discourse", "dobj", - "expl", "iobj", "mark", "mwe", "neg", "nmod", "nmod:npmod", "nmod:poss", - "nmod:tmod", "nsubj", "nsubjpass", "nummod", "parataxis", "punct", "root", - "xcomp" }; - - String[] unmappedDep = { "acl:relcl", "cc:preconj", "compound:prt", "det:predet", - "nmod:npmod", "nmod:poss", "nmod:tmod" }; + String[] dependencies = { "[ 0, 3]DET(det,basic) D[0,3](The) G[4,8](ball)", + "[ 4, 8]NSUBJPASS(nsubj:pass,basic) D[4,8](ball) G[13,19](kicked)", + "[ 9, 12]AUXPASS(aux:pass,basic) D[9,12](was) G[13,19](kicked)", + "[ 13, 19]ROOT(root,basic) D[13,19](kicked) G[13,19](kicked)", + "[ 20, 22]PREP(case,basic) D[20,22](by) G[23,27](John)", + "[ 23, 27]AGENT(obl:agent,basic) D[23,27](John) G[13,19](kicked)", + "[ 28, 29]PUNCT(punct,basic) D[28,29](.) G[13,19](kicked)" }; assertDependencies(dependencies, select(jcas, Dependency.class)); - assertTagset(CoreNlpPosTagger.class, POS.class, "ptb", PTB_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, POS.class, "ptb", PTB_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, Dependency.class, "universal", depTags, jcas); - assertTagsetMapping(Dependency.class, "universal", unmappedDep, jcas); } @Test public void testFrenchUniversalDependencies() throws Exception { + // Uses the default French POS tagger which must match the UD dependency parser JCas jcas = runTest("fr", "ud", "Nous avons besoin d' une phrase par exemple très " + "compliqué , qui contient des constituants que de nombreuses dépendances et que " + "possible ."); - String[] dependencies = { "[ 0, 4]ROOT(root,basic) D[0,4](Nous) G[0,4](Nous)", - "[ 5, 10]Dependency(nmod,basic) D[5,10](avons) G[0,4](Nous)", - "[ 11, 17]DOBJ(dobj,basic) D[11,17](besoin) G[5,10](avons)", + String[] dependencies = { "[ 0, 4]NSUBJ(nsubj,basic) D[0,4](Nous) G[5,10](avons)", + "[ 5, 10]ROOT(root,basic) D[5,10](avons) G[5,10](avons)", + "[ 11, 17]DOBJ(obj,basic) D[11,17](besoin) G[5,10](avons)", "[ 18, 20]PREP(case,basic) D[18,20](d') G[25,31](phrase)", "[ 21, 24]DET(det,basic) D[21,24](une) G[25,31](phrase)", "[ 25, 31]Dependency(nmod:d',basic) D[25,31](phrase) G[11,17](besoin)", - "[ 32, 35]ADVMOD(advmod,basic) D[32,35](par) G[25,31](phrase)", - "[ 36, 43]MWE(mwe,basic) D[36,43](exemple) G[32,35](par)", + "[ 32, 35]PREP(case,basic) D[32,35](par) G[36,43](exemple)", + "[ 36, 43]Dependency(obl:mod,basic) D[36,43](exemple) G[49,58](compliqué)", "[ 44, 48]ADVMOD(advmod,basic) D[44,48](très) G[49,58](compliqué)", - "[ 49, 58]AMOD(amod,basic) D[49,58](compliqué) G[36,43](exemple)", - "[ 59, 60]DEP(dep,basic) D[59,60](,) G[49,58](compliqué)", + "[ 49, 58]Dependency(acl,basic) D[49,58](compliqué) G[5,10](avons)", + "[ 59, 60]PUNCT(punct,basic) D[59,60](,) G[65,73](contient)", "[ 61, 64]NSUBJ(nsubj,basic) D[61,64](qui) G[65,73](contient)", - "[ 65, 73]Dependency(acl:relcl,basic) D[65,73](contient) G[59,60](,)", + "[ 65, 73]CONJ(conj,basic) D[65,73](contient) G[49,58](compliqué)", "[ 74, 77]DET(det,basic) D[74,77](des) G[78,90](constituants)", - "[ 78, 90]DOBJ(dobj,basic) D[78,90](constituants) G[65,73](contient)", + "[ 78, 90]DOBJ(obj,basic) D[78,90](constituants) G[65,73](contient)", "[ 91, 94]PREP(case,basic) D[91,94](que) G[109,120](dépendances)", "[ 95, 97]DET(det,basic) D[95,97](de) G[109,120](dépendances)", "[ 98,108]AMOD(amod,basic) D[98,108](nombreuses) G[109,120](dépendances)", - "[109,120]DEP(dep,basic) D[109,120](dépendances) G[78,90](constituants)", - "[121,123]CC(cc,basic) D[121,123](et) G[109,120](dépendances)", - "[124,127]COP(cop,basic) D[124,127](que) G[128,136](possible)", - "[128,136]CCOMP(ccomp,basic) D[128,136](possible) G[121,123](et)", - "[137,138]PUNCT(punct,basic) D[137,138](.) G[128,136](possible)" }; - - String[] depTags = { "acl", "acl:relcl", "advcl", "advmod", "amod", "appos", "aux", - "auxpass", "case", "cc", "ccomp", "compound", "conj", "cop", "csubj", "dep", "det", - "discourse", "dislocated", "dobj", "expl", "foreign", "goeswith", "iobj", "mark", - "mwe", "name", "neg", "nmod", "nmod:poss", "nsubj", "nsubjpass", "nummod", - "parataxis", "punct", "remnant", "reparandum", "root", "vocative", "xcomp" }; - - String[] unmappedDep = { "acl:relcl", "nmod:poss" }; + "[109,120]Dependency(obl:que,basic) D[109,120](dépendances) G[78,90](constituants)", + "[121,123]CC(cc,basic) D[121,123](et) G[128,136](possible)", + "[124,127]ADVMOD(advmod,basic) D[124,127](que) G[128,136](possible)", + "[128,136]CONJ(conj:et,basic) D[128,136](possible) G[109,120](dépendances)", + "[137,138]PUNCT(punct,basic) D[137,138](.) G[5,10](avons)" }; + + String[] depTags = { "acl", "acl:relcl", "advcl", "advcl:cleft", "advmod", "amod", "appos", + "aux", "aux:caus", "aux:pass", "case", "cc", "ccomp", "compound", "conj", "cop", + "csubj", "csubj:pass", "dep", "det", "discourse", "dislocated", "expl", "expl:pass", + "fixed", "flat", "flat:foreign", "flat:name", "goeswith", "iobj", "iobj:agent", + "mark", "nmod", "nmod:range", "nsubj", "nsubj:caus", "nsubj:pass", "nummod", "obj", + "obj:agent", "obl", "obl:agent", "obl:arg", "obl:mod", "orphan", "parataxis", + "punct", "reparandum", "root", "vocative", "xcomp" }; + + String[] unmappedDep = { "advcl:cleft", "aux:caus", "expl:pass", "flat:foreign", + "flat:name", "iobj:agent", "nmod:range", "nsubj:caus", "obj:agent", "obl:arg", + "obl:mod" }; assertDependencies(dependencies, select(jcas, Dependency.class)); - assertTagset(CoreNlpPosTagger.class, POS.class, "corenlp34", CORENLP34_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, POS.class, "universal", UNIVERSAL_POS_TAGS, - jcas); - assertTagset(CoreNlpDependencyParser.class, Dependency.class, "universal", depTags, jcas); - assertTagsetMapping(Dependency.class, "universal", unmappedDep, jcas); + assertTagset(CoreNlpPosTagger.class, POS.class, "ud2", UD2_POS_TAGS, jcas); + assertTagset(CoreNlpDependencyParser.class, POS.class, "ud2", UD2_POS_TAGS, jcas); + assertTagset(CoreNlpDependencyParser.class, Dependency.class, "ud2", depTags, jcas); + assertTagsetMapping(Dependency.class, "ud2", unmappedDep, jcas); } @Test public void testGermanUniversalDependencies() throws Exception { + // Uses the default German POS tagger which must match the UD dependency parser JCas jcas = runTest("de", "ud", "Wir brauchen ein sehr kompliziertes Beispiel , welches " + "möglichst viele Konstituenten und Dependenzen beinhaltet ."); @@ -273,36 +207,31 @@ public void testGermanUniversalDependencies() throws Exception "[ 13, 16]DET(det,basic) D[13,16](ein) G[36,44](Beispiel)", "[ 17, 21]ADVMOD(advmod,basic) D[17,21](sehr) G[22,35](kompliziertes)", "[ 22, 35]AMOD(amod,basic) D[22,35](kompliziertes) G[36,44](Beispiel)", - "[ 36, 44]DOBJ(dobj,basic) D[36,44](Beispiel) G[4,12](brauchen)", - "[ 45, 46]PUNCT(punct,basic) D[45,46](,) G[4,12](brauchen)", + "[ 36, 44]DOBJ(obj,basic) D[36,44](Beispiel) G[4,12](brauchen)", + "[ 45, 46]PUNCT(punct,basic) D[45,46](,) G[101,111](beinhaltet)", "[ 47, 54]NSUBJ(nsubj,basic) D[47,54](welches) G[101,111](beinhaltet)", "[ 55, 64]ADVMOD(advmod,basic) D[55,64](möglichst) G[65,70](viele)", - "[ 65, 70]AMOD(amod,basic) D[65,70](viele) G[71,84](Konstituenten)", - "[ 71, 84]DOBJ(dobj,basic) D[71,84](Konstituenten) G[101,111](beinhaltet)", - "[ 85, 88]CC(cc,basic) D[85,88](und) G[71,84](Konstituenten)", - "[ 89,100]CONJ(conj,basic) D[89,100](Dependenzen) G[71,84](Konstituenten)", - "[101,111]Dependency(acl,basic) D[101,111](beinhaltet) G[4,12](brauchen)", + "[ 65, 70]DET(det,basic) D[65,70](viele) G[71,84](Konstituenten)", + "[ 71, 84]DOBJ(obj,basic) D[71,84](Konstituenten) G[101,111](beinhaltet)", + "[ 85, 88]CC(cc,basic) D[85,88](und) G[89,100](Dependenzen)", + "[ 89,100]CONJ(conj:und,basic) D[89,100](Dependenzen) G[71,84](Konstituenten)", + "[101,111]Dependency(acl,basic) D[101,111](beinhaltet) G[36,44](Beispiel)", "[112,113]PUNCT(punct,basic) D[112,113](.) G[4,12](brauchen)" }; - String[] depTags = { "acl", "advcl", "advmod", "amod", "appos", "aux", "auxpass", "case", - "cc", "ccomp", "compound", "conj", "cop", "csubj", "csubjpass", "dep", "det", - "dobj", "expl", "iobj", "mark", "mwe", "name", "neg", "nmod", "nmod:poss", "nsubj", - "nsubjpass", "nummod", "parataxis", "punct", "root", "xcomp" }; - - String[] unmappedDep = { "nmod:poss" }; + String[] depTags = { "acl", "acl:relcl", "advcl", "advmod", "amod", "appos", "aux", + "aux:pass", "case", "cc", "ccomp", "compound", "compound:prt", "conj", "cop", + "csubj", "csubj:pass", "dep", "det", "det:poss", "discourse", "expl", "expl:pv", + "fixed", "flat", "goeswith", "mark", "nmod", "nmod:poss", "nsubj", "nsubj:outer", + "nsubj:pass", "nummod", "obj", "obl", "obl:agent", "obl:arg", "obl:tmod", "orphan", + "parataxis", "punct", "reparandum", "root", "vocative", "xcomp" }; - String[] depParserPosTags = { "$,", "$.", "$[", "ADJA", "ADJD", "ADV", "APPO", "APPR", - "APPRART", "APZR", "ART", "CARD", "FM", "ITJ", "KOKOM", "KON", "KOUI", "KOUS", "NE", - "NN", "PDAT", "PDS", "PIAT", "PIDAT", "PIS", "PPER", "PPOSAT", "PRELAT", "PRELS", - "PRF", "PROAV", "PTKA", "PTKANT", "PTKNEG", "PTKVZ", "PTKZU", "PWAT", "PWAV", "PWS", - "TRUNC", "VAFIN", "VAIMP", "VAINF", "VAPP", "VMFIN", "VMINF", "VVFIN", "VVIMP", - "VVINF", "VVIZU", "VVPP", "XY" }; + String[] unmappedDep = { "expl:pv", "nsubj:outer", "obl:arg" }; assertDependencies(dependencies, select(jcas, Dependency.class)); - assertTagset(CoreNlpPosTagger.class, POS.class, "stts", GERMAN_POS_TAGS, jcas); - assertTagset(CoreNlpDependencyParser.class, POS.class, "stts", depParserPosTags, jcas); - assertTagset(CoreNlpDependencyParser.class, Dependency.class, "universal", depTags, jcas); - assertTagsetMapping(Dependency.class, "universal", unmappedDep, jcas); + assertTagset(CoreNlpPosTagger.class, POS.class, "ud2", UD2_POS_TAGS, jcas); + assertTagset(CoreNlpDependencyParser.class, POS.class, "ud2", UD2_POS_TAGS, jcas); + assertTagset(CoreNlpDependencyParser.class, Dependency.class, "ud2", depTags, jcas); + assertTagsetMapping(Dependency.class, "ud2", unmappedDep, jcas); } @Test @@ -501,13 +430,21 @@ public void testEnglishPtbConllDependencies() throws Exception private JCas runTest(String aLanguage, String aVariant, String aText, Object... aExtraParams) throws Exception + { + return runTest(aLanguage, null, aVariant, aText, aExtraParams); + } + + private JCas runTest(String aLanguage, String aTaggerVariant, String aVariant, String aText, + Object... aExtraParams) + throws Exception { AssumeResource.assumeResource(CoreNlpDependencyParser.class, "depparser", aLanguage, aVariant); AggregateBuilder aggregate = new AggregateBuilder(); - aggregate.add(createEngineDescription(CoreNlpPosTagger.class)); + aggregate.add(createEngineDescription(CoreNlpPosTagger.class, + CoreNlpPosTagger.PARAM_VARIANT, aTaggerVariant)); Object[] params = new Object[] { CoreNlpDependencyParser.PARAM_VARIANT, aVariant, CoreNlpDependencyParser.PARAM_PRINT_TAGSET, true }; params = ArrayUtils.addAll(params, aExtraParams); diff --git a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpLemmatizerTest.java b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpLemmatizerTest.java index 0af050def2..bc1f8c519e 100644 --- a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpLemmatizerTest.java +++ b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpLemmatizerTest.java @@ -53,6 +53,14 @@ public void testEnglish() throws Exception "possible", "." }); } + @Test + public void testBrackets() throws Exception + { + // PTB3 escaping is disabled by default, so brackets are not lemmatized as -lrb-/-rrb- + runTest("en", "This is a ( test ) .", + new String[] { "this", "be", "a", "(", "test", ")", "." }); + } + @Test public void testNotEnglish() throws Exception { diff --git a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpParserTest.java b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpParserTest.java index 1585b66555..fb9e19195d 100644 --- a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpParserTest.java +++ b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpParserTest.java @@ -81,6 +81,15 @@ public class CoreNlpParserTest private static final String[] ENGLISH_CONSTITUENT_UNMAPPED = {}; + private static final String[] ENGLISH_UD2_DEPENDENCY_TAGS = { "acl", "acl:relcl", "advcl", + "advmod", "amod", "appos", "arg", "aux", "aux:pass", "case", "cc", "cc:preconj", + "ccomp", "comp", "compound", "compound:prt", "conj", "cop", "csubj", "csubj:pass", + "csubj:xsubj", "csubjpass:xsubj", "dep", "det", "det:predet", "det:qmod", "discourse", + "expl", "fixed", "flat", "goeswith", "gov", "iobj", "list", "mark", "mod", "name", + "neg", "nmod", "nmod:poss", "nsubj", "nsubj:pass", "nsubj:pass:xsubj", "nsubj:xsubj", + "nummod", "obj", "obl", "obl:agent", "obl:npmod", "obl:tmod", "orphan", "parataxis", + "pred", "prep", "punct", "ref", "rel", "sdep", "subj", "xcomp" }; + private static final String[] ENGLISH_DEPENDENCY_TAGS = { "acomp", "advcl", "advmod", "agent", "amod", "appos", "arg", "aux", "auxpass", "cc", "ccomp", "comp", "conj", "cop", "csubj", "csubjpass", "dep", "det", "discourse", "dobj", "expl", "goeswith", "gov", "iobj", @@ -199,8 +208,11 @@ public void testGermanFactored() throws Exception @Test public void testEnglishPcfg() throws Exception { - JCas jcas = runTest("en", "pcfg", "We need a very complicated example sentence , which " - + "contains as many constituents and dependencies as possible ."); + // Stanford Dependencies are no longer the default + JCas jcas = runTest("en", "pcfg", + "We need a very complicated example sentence , which " + + "contains as many constituents and dependencies as possible .", + CoreNlpParser.PARAM_ORIGINAL_DEPENDENCIES, true); String[] constituentMapped = { "ADJP 10,26", "ADJP 102,110", "NP 0,2", "NP 64,98", "NP 8,110", "NP 8,43", "PP 61,98", "PP 99,110", "ROOT 0,112", "S 0,112", "S 52,110", @@ -269,15 +281,17 @@ public void testEnglishFactored() throws Exception "[ 8, 9]DET(det,basic) D[8,9](a) G[35,43](sentence)", "[ 10, 14]ADVMOD(advmod,basic) D[10,14](very) G[15,26](complicated)", "[ 15, 26]AMOD(amod,basic) D[15,26](complicated) G[35,43](sentence)", - "[ 27, 34]NN(nn,basic) D[27,34](example) G[35,43](sentence)", - "[ 35, 43]DOBJ(dobj,basic) D[35,43](sentence) G[3,7](need)", + "[ 27, 34]NN(compound,basic) D[27,34](example) G[35,43](sentence)", + "[ 35, 43]DOBJ(obj,basic) D[35,43](sentence) G[3,7](need)", "[ 46, 51]NSUBJ(nsubj,basic) D[46,51](which) G[52,60](contains)", - "[ 52, 60]RCMOD(rcmod,basic) D[52,60](contains) G[35,43](sentence)", + "[ 52, 60]RCMOD(acl:relcl,basic) D[52,60](contains) G[35,43](sentence)", "[ 61, 63]ADVMOD(advmod,basic) D[61,63](as) G[64,68](many)", "[ 64, 68]AMOD(amod,basic) D[64,68](many) G[69,81](constituents)", - "[ 69, 81]DOBJ(dobj,basic) D[69,81](constituents) G[52,60](contains)", - "[ 86, 98]CONJ(conj_and,basic) D[86,98](dependencies) G[69,81](constituents)", - "[102,110]PREP(prep_as,basic) D[102,110](possible) G[52,60](contains)" }; + "[ 69, 81]DOBJ(obj,basic) D[69,81](constituents) G[52,60](contains)", + "[ 82, 85]CC(cc,basic) D[82,85](and) G[86,98](dependencies)", + "[ 86, 98]CONJ(conj:and,basic) D[86,98](dependencies) G[69,81](constituents)", + "[ 99,101]PREP(case,basic) D[99,101](as) G[102,110](possible)", + "[102,110]ADVCL(advcl,basic) D[102,110](possible) G[52,60](contains)" }; String[] posMapped = { "POS_PRON", "POS_VERB", "POS_DET", "POS_ADV", "POS_VERB", "POS_NOUN", "POS_NOUN", "POS_PUNCT", "POS_DET", "POS_VERB", "POS_ADV", "POS_ADJ", "POS_NOUN", @@ -301,8 +315,13 @@ public void testEnglishFactored() throws Exception assertTagsetMapping(POS.class, "ptb", ENGLISH_POS_UNMAPPED, jcas); assertTagset(Constituent.class, "ptb", ENGLISH_CONSTITUENT_TAGS, jcas); assertTagsetMapping(Constituent.class, "ptb", ENGLISH_CONSTITUENT_UNMAPPED, jcas); - assertTagset(Dependency.class, "stanford341", ENGLISH_DEPENDENCY_TAGS, jcas); - assertTagsetMapping(Dependency.class, "stanford341", unmappedDep, jcas); + assertTagset(Dependency.class, "ud2", ENGLISH_UD2_DEPENDENCY_TAGS, jcas); + // CoreNLP-internal relations, enhanced labels and UD v1 leftovers in the CoreNLP relation + // list. Subtypes fall back to their base relation during mapping. + String[] unmappedUd2Dep = { "arg", "comp", "csubj:xsubj", "csubjpass:xsubj", "det:qmod", + "gov", "mod", "name", "neg", "nsubj:pass:xsubj", "nsubj:xsubj", "pred", "prep", + "ref", "rel", "sdep", "subj" }; + assertTagsetMapping(Dependency.class, "ud2", unmappedUd2Dep, jcas); } // CoreNlpParser PARAM_KEEP_PUNCTUATION has no effect #965 @@ -802,7 +821,9 @@ public void testFrench2() throws Exception @Test public void testChineseFactored() throws Exception { - JCas jcas = runTest("zh", "factored", "我们 需要 一个 非常 复杂 的 句子 例如 其中 包含 许多 成分 和 尽可能 的 依赖 。"); + // Stanford Dependencies are no longer the default + JCas jcas = runTest("zh", "factored", "我们 需要 一个 非常 复杂 的 句子 例如 其中 包含 许多 成分 和 尽可能 的 依赖 。", + CoreNlpParser.PARAM_ORIGINAL_DEPENDENCIES, true); String[] constituentMapped = { "ADJP 12,14", "ADJP 9,14", "ADVP 20,22", "ADVP 37,40", "ADVP 9,11", "NP 0,2", "NP 17,19", "NP 23,25", "NP 29,34", "NP 32,34", "NP 6,19", @@ -891,19 +912,19 @@ public void testChineseXinhuaFactored() throws Exception String[] dependencies = { "[ 0, 2]NSUBJ(nsubj,basic) D[0,2](我们) G[3,5](需要)", "[ 3, 5]ROOT(root,basic) D[3,5](需要) G[3,5](需要)", - "[ 6, 8]Dependency(nummod,basic) D[6,8](一个) G[43,45](依赖)", + "[ 6, 8]DEP(dep,basic) D[6,8](一个) G[43,45](依赖)", "[ 9, 11]ADVMOD(advmod,basic) D[9,11](非常) G[12,14](复杂)", - "[ 12, 14]RCMOD(rcmod,basic) D[12,14](复杂) G[17,19](句子)", - "[ 15, 16]Dependency(cpm,basic) D[15,16](的) G[12,14](复杂)", + "[ 12, 14]AMOD(amod,basic) D[12,14](复杂) G[17,19](句子)", + "[ 15, 16]MARK(mark,basic) D[15,16](的) G[12,14](复杂)", "[ 17, 19]NSUBJ(nsubj,basic) D[17,19](句子) G[26,28](包含)", "[ 20, 22]ADVMOD(advmod,basic) D[20,22](例如) G[26,28](包含)", "[ 23, 25]NSUBJ(nsubj,basic) D[23,25](其中) G[26,28](包含)", - "[ 26, 28]RCMOD(rcmod,basic) D[26,28](包含) G[43,45](依赖)", - "[ 29, 31]Dependency(nummod,basic) D[29,31](许多) G[32,34](成分)", + "[ 26, 28]Dependency(acl,basic) D[26,28](包含) G[43,45](依赖)", + "[ 29, 31]DEP(dep,basic) D[29,31](许多) G[32,34](成分)", "[ 32, 34]DOBJ(dobj,basic) D[32,34](成分) G[26,28](包含)", "[ 35, 36]CC(cc,basic) D[35,36](和) G[26,28](包含)", "[ 37, 40]CONJ(conj,basic) D[37,40](尽可能) G[26,28](包含)", - "[ 41, 42]Dependency(cpm,basic) D[41,42](的) G[26,28](包含)", + "[ 41, 42]MARK(mark,basic) D[41,42](的) G[26,28](包含)", "[ 43, 45]DOBJ(dobj,basic) D[43,45](依赖) G[3,5](需要)" }; String[] posMapped = { "POS_PRON", "POS_VERB", "POS_NUM", "POS_ADJ", "POS_VERB", "POS_PART", diff --git a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpPosTaggerTest.java b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpPosTaggerTest.java index b72246e27e..52a3eb562e 100644 --- a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpPosTaggerTest.java +++ b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/CoreNlpPosTaggerTest.java @@ -75,12 +75,17 @@ public void testEnglishExtra() throws Exception @Test public void testGerman() throws Exception { - runTest("de", "Das ist ein Test .", new String[] { "PDS", "VAFIN", "ART", "NN", "$." }, + // The default German model is the UD model which matches the German UD dependency parser + runTest("de", "Das ist ein Test .", new String[] { "PRON", "AUX", "DET", "NOUN", "PUNCT" }, + new String[] { "POS_PRON", "POS_AUX", "POS_DET", "POS_NOUN", "POS_PUNCT" }); + + runTest("de", "fast", "Das ist ein Test .", + new String[] { "PDS", "VAFIN", "ART", "NN", "$." }, new String[] { "POS_PRON", "POS_VERB", "POS_DET", "POS_NOUN", "POS_PUNCT" }); runTest("de", "ud", "Das ist ein Test .", - new String[] { "PRON", "VERB", "DET", "NOUN", "PUNCT" }, - new String[] { "POS_PRON", "POS_VERB", "POS_DET", "POS_NOUN", "POS_PUNCT" }); + new String[] { "PRON", "AUX", "DET", "NOUN", "PUNCT" }, + new String[] { "POS_PRON", "POS_AUX", "POS_DET", "POS_NOUN", "POS_PUNCT" }); runTest("de", "hgc", "Das ist ein Test .", new String[] { "PDS", "VAFIN", "ART", "NN", "$." }, @@ -103,7 +108,7 @@ public void testGerman() throws Exception @Test public void testFrench() throws Exception { - JCas jcas = runTest("fr", null, "Nous avons besoin d' une phrase par exemple très " + JCas jcas = runTest("fr", "default", "Nous avons besoin d' une phrase par exemple très " + "compliqué , qui contient des constituants que de nombreuses dépendances et que " + "possible ."); @@ -134,13 +139,16 @@ public void testFrench() throws Exception @Test public void testFrench2() throws Exception { + // The default French model is the UD model which matches the French UD dependency parser. + // CoreNLP 4.x expects multi-word tokens to be split (e.g. "du" into "de le") which our + // tokenization does not do, so "du" is tagged as DET and "français" as ADJ here. JCas jcas = runTest("fr", null, "La traduction d' un texte du français vers l' anglais ."); - String[] posOriginal = { "DET", "NC", "P", "DET", "NC", "P", "NC", "P", "DET", "NC", - "PUNC" }; + String[] posOriginal = { "DET", "NOUN", "ADP", "DET", "NOUN", "DET", "ADJ", "ADP", "DET", + "NOUN", "PUNCT" }; - String[] posMapped = { "POS_DET", "POS_NOUN", "POS_ADP", "POS_DET", "POS_NOUN", "POS_ADP", - "POS_NOUN", "POS_ADP", "POS_DET", "POS_NOUN", "POS_PUNCT" }; + String[] posMapped = { "POS_DET", "POS_NOUN", "POS_ADP", "POS_DET", "POS_NOUN", "POS_DET", + "POS_ADJ", "POS_ADP", "POS_DET", "POS_NOUN", "POS_PUNCT" }; AssertAnnotations.assertPOS(posMapped, posOriginal, select(jcas, POS.class)); } diff --git a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/internal/DKPro2CoreNlpTest.java b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/internal/DKPro2CoreNlpTest.java new file mode 100644 index 0000000000..2f96223d76 --- /dev/null +++ b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/internal/DKPro2CoreNlpTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Technische Universität Darmstadt under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. + * + * This program 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. + * + * This program 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.dkpro.core.corenlp.internal; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.dkpro.core.corenlp.internal.DKPro2CoreNlp.META_PTB3_ESCAPING; +import static org.dkpro.core.corenlp.internal.DKPro2CoreNlp.resolvePtb3Escaping; + +import java.util.Properties; + +import org.junit.jupiter.api.Test; + +public class DKPro2CoreNlpTest +{ + @Test + public void thatExplicitPtb3EscapingSettingWins() + { + assertThat(resolvePtb3Escaping(true, metadata("false"))).isTrue(); + assertThat(resolvePtb3Escaping(false, metadata("true"))).isFalse(); + assertThat(resolvePtb3Escaping(false, null)).isFalse(); + } + + @Test + public void thatPtb3EscapingIsTakenFromModelMetadata() + { + assertThat(resolvePtb3Escaping(null, metadata("false"))).isFalse(); + assertThat(resolvePtb3Escaping(null, metadata("true"))).isTrue(); + } + + @Test + public void thatPtb3EscapingIsEnabledByDefault() + { + assertThat(resolvePtb3Escaping(null, new Properties())).isTrue(); + assertThat(resolvePtb3Escaping(null, null)).isTrue(); + } + + private static Properties metadata(String aValue) + { + Properties props = new Properties(); + props.setProperty(META_PTB3_ESCAPING, aValue); + return props; + } +} diff --git a/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/internal/PosTagsetCompatibilityCheckerTest.java b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/internal/PosTagsetCompatibilityCheckerTest.java new file mode 100644 index 0000000000..a00ab32473 --- /dev/null +++ b/dkpro-core-corenlp-gpl/src/test/java/org/dkpro/core/corenlp/internal/PosTagsetCompatibilityCheckerTest.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Technische Universität Darmstadt under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. + * + * This program 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. + * + * This program 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.dkpro.core.corenlp.internal; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Properties; +import java.util.Set; + +import org.apache.uima.fit.factory.JCasFactory; +import org.apache.uima.jcas.JCas; +import org.junit.jupiter.api.Test; + +import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token; + +public class PosTagsetCompatibilityCheckerTest +{ + private static final Set UD2_TAGS = Set.of("ADJ", "ADP", "ADV", "AUX", "CCONJ", "DET", + "INTJ", "NOUN", "NUM", "PART", "PRON", "PROPN", "PUNCT", "SCONJ", "SYM", "VERB", "X"); + + @Test + public void thatIncompatibleTagsetIsReportedOnce() throws Exception + { + PosTagsetCompatibilityChecker sut = new PosTagsetCompatibilityChecker(); + Object model = new Object(); + sut.registerModel(model, UD2_TAGS); + + JCas jcas = createJCas("PPER", "VVFIN", "NN", "$."); + + assertThat(sut.check(jcas, model, metadata("ud2"))).contains("4 of 4").contains("[ud2]") + .contains("PPER"); + assertThat(sut.check(jcas, model, metadata("ud2"))).isNull(); + } + + @Test + public void thatOccasionalUnknownTagsAreNotReported() throws Exception + { + PosTagsetCompatibilityChecker sut = new PosTagsetCompatibilityChecker(); + Object model = new Object(); + sut.registerModel(model, UD2_TAGS); + + JCas jcas = createJCas("PRON", "VERB", "NOUN", "XYZ"); + + assertThat(sut.check(jcas, model, metadata("ud2"))).isNull(); + } + + @Test + public void thatUnregisteredModelIsNotReported() throws Exception + { + PosTagsetCompatibilityChecker sut = new PosTagsetCompatibilityChecker(); + + JCas jcas = createJCas("PPER", "VVFIN", "NN", "$."); + + assertThat(sut.check(jcas, new Object(), metadata("ud2"))).isNull(); + } + + private static Properties metadata(String aPosTagset) + { + Properties props = new Properties(); + props.setProperty("language", "de"); + props.setProperty("variant", "ud"); + props.setProperty("pos.tagset", aPosTagset); + return props; + } + + private static JCas createJCas(String... aTags) throws Exception + { + JCas jcas = JCasFactory.createJCas(); + StringBuilder text = new StringBuilder(); + for (String tag : aTags) { + int begin = text.length(); + text.append("w "); + Token token = new Token(jcas, begin, begin + 1); + POS pos = new POS(jcas, begin, begin + 1); + pos.setPosValue(tag); + pos.addToIndexes(); + token.setPos(pos); + token.addToIndexes(); + } + jcas.setDocumentText(text.toString()); + return jcas; + } +} diff --git a/dkpro-core-gate-asl/src/scripts/build.xml b/dkpro-core-gate-asl/src/scripts/build.xml index 0bcfcb65b1..143fdff141 100644 --- a/dkpro-core-gate-asl/src/scripts/build.xml +++ b/dkpro-core-gate-asl/src/scripts/build.xml @@ -42,11 +42,19 @@ - + + + - + - + @@ -71,12 +79,18 @@ - + + - + - - + + @@ -99,14 +113,15 @@ - - + + + - + - - + \ No newline at end of file diff --git a/dkpro-core-hunpos-asl/src/scripts/build.xml b/dkpro-core-hunpos-asl/src/scripts/build.xml index d5936483a7..b3725c9b35 100644 --- a/dkpro-core-hunpos-asl/src/scripts/build.xml +++ b/dkpro-core-hunpos-asl/src/scripts/build.xml @@ -298,7 +298,7 @@ diff --git a/dkpro-core-maltparser-asl/src/scripts/build.xml b/dkpro-core-maltparser-asl/src/scripts/build.xml index 84131e2f6c..1fdd13d0b2 100644 --- a/dkpro-core-maltparser-asl/src/scripts/build.xml +++ b/dkpro-core-maltparser-asl/src/scripts/build.xml @@ -158,7 +158,7 @@ - 2012-03-12 | now | 6f81de28b4c3f1f309a578d7d21fcb6e --> @@ -123,7 +123,7 @@ - 2012-06-16 | now | 595322af76e464a647b745b463847008 --> @@ -160,7 +160,7 @@ - 2012-06-16 | now | 1e8a9b9ce05d91abbd1d1d9f4192fdeb --> @@ -1513,7 +1513,7 @@ - 2012-06-16 | now | 81a3bf1d4c552db190a90630acc4d15f -->