Skip to content

Commit f270553

Browse files
authored
Merge pull request #31 from anka-213/anka-213/issue28
Feature request: pattern matching also on XPOS and MISC
2 parents bd6d054 + 71e841e commit f270553

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

UD2GF.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ udtree2devtree = markClosest . initialize
500500
devLemma = udLEMMA un,
501501
devPOS = udUPOS un,
502502
devFeats = udFEATS un ++ [UDData "LEMMA" [udLEMMA un]
503-
,UDData "FORM" [udFORM un]],
503+
,UDData "FORM" [udFORM un]
504+
,UDData "XPOS" [udXPOS un]]
505+
++ map (\udData -> udData{udArg = "MISC-" ++ udArg udData}) (udMISC un),
504506
devLabel = udDEPREL un,
505507
devIndex = udID un,
506508
devClosest = udIdRoot, --- junk value

UDPatterns.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import UDConcepts
55
import GFConcepts
66
import UDAnalysis
77
import UDOptions
8+
import Data.Maybe (listToMaybe)
9+
import Data.List (intercalate)
810

911

1012
showMatchesInUDSentence :: Opts -> UDPattern -> UDSentence -> String
@@ -43,6 +45,8 @@ data UDPattern =
4345
FORM String
4446
| LEMMA String
4547
| POS String
48+
| XPOS String
49+
| MISC String String
4650
| FEATS String -- feature list matches exactly
4751
| FEATS_ String -- a sublist of features matches exactly
4852
| DEPREL String -- deprel matches exactly
@@ -70,6 +74,8 @@ ifMatchUDPattern patt tree@(RTree node subtrees) = case patt of
7074
FORM s -> matchString s (udFORM node)
7175
LEMMA s -> matchString s (udLEMMA node)
7276
POS s -> matchString s (udUPOS node)
77+
XPOS s -> matchString s (udXPOS node)
78+
MISC name s -> maybe False (matchString s) $ listToMaybe [ intercalate "," vals | UDData arg vals <- udMISC node , arg == name ]
7379
FEATS udds -> udFEATS node == prs udds
7480
FEATS_ udds ->
7581
let uddlist = prs udds in
@@ -123,6 +129,8 @@ data UDReplacement =
123129
REPLACE_FORM String String
124130
| REPLACE_LEMMA String String
125131
| REPLACE_POS String String
132+
| REPLACE_XPOS String String
133+
| REPLACE_MISC String String String
126134
| REPLACE_DEPREL String String
127135
| REPLACE_DEPREL_ String String
128136
| REPLACE_FEATS String String
@@ -143,6 +151,8 @@ replaceWithUDPattern rep tree@(RTree node subtrs) = case rep of
143151
REPLACE_FORM old new | ifMatchUDPattern (FORM old) tree -> true $ tree{root = node{udFORM = new}}
144152
REPLACE_LEMMA old new | ifMatchUDPattern (LEMMA old) tree -> true $ tree{root = node{udLEMMA = new}}
145153
REPLACE_POS old new | ifMatchUDPattern (POS old) tree -> true $ tree{root = node{udUPOS = new}}
154+
REPLACE_XPOS old new | ifMatchUDPattern (XPOS old) tree -> true $ tree{root = node{udXPOS = new}}
155+
REPLACE_MISC name old new | ifMatchUDPattern (MISC name old) tree -> true $ tree{root = node{udMISC = map (\ud -> if udArg ud == name then ud{udVals = getSeps ',' new} else ud) (udMISC node)}}
146156
REPLACE_DEPREL old new | ifMatchUDPattern (DEPREL old) tree -> true $ tree{root = node{udDEPREL = new}}
147157
REPLACE_DEPREL_ old new | ifMatchUDPattern (DEPREL_ old) tree -> true $ tree{root = node{udDEPREL = new}}
148158
REPLACE_FEATS old new | ifMatchUDPattern (FEATS old) tree -> true $ tree{root = node{udFEATS = prs new}}

0 commit comments

Comments
 (0)