我已经开始在SAS中使用PRX代码来识别输入到我正在使用的数据库中的自由文本短语。我识别的一个典型短语是:“阳性的修正霍奇试验”或“阳性的修正霍奇试验”。这些短语有时会嵌入到大的文本字符串中。我不想标记的是那些写着“之前的阳性霍奇测试”的短语。我已经阅读了一些文档,以实现一个负向回溯,不标记包含“以前”的短语,但它并不像我预期的那样。
如果prxmatch("/pos\w+ (for)?(by)?\s?(the)?\s?(modi|hod|mht)/i") >0,则hodge_id = 1;
上面的PRX代码将匹配下面的所有短语:“阳性修改的hodge”“以前的阳性hodge测试”“确认的阳性hodge碳青霉烯酶”“修改的hodge测试的阳性”“修改的hodge的阳性”
if prxmatch("/pos\w+ (for)?(by)?\s?(the)?\s?(modi|hod|mht)/i") > 0 then
hodge_id = 1; /* Without lookback */
if prxmatch("/(?<!previous)\s*pos\w+ (for)?(by)?\s?(the)?\s?
(modi|hod|mht)/i") > 0 then hodge_id = 1; /* With lookbook */使用阴性回看,我期望标记:“阳性改良霍奇”“确认阳性霍奇碳青霉烯酶”“改良霍奇试验阳性”“改良霍奇阳性”
但不是:“之前的阳性霍奇测试”
发生的情况是,它省略了包括“以前”的短语,但也省略了第一个短语“积极修改的hodge”。
我的PRX还处于初级阶段,所以任何关于清理/简化它的建议都是值得感谢的。
发布于 2019-01-26 10:09:45
你们已经很接近了。
/*
you need to have
(?<!previous\s) or (?<!previous)\s
instead of (?<!previous)\s*
*/
data have;
length string $200.;
infile datalines;
input string & $ ;
datalines;
this is cool and nice positive modified hodge wow so nice
this is wow confirmed positive hodge carbapenemase
now this positive for modified hodge test and later
cool is my name positive by the modified hodge hello
wow and wow previous positive hodge test
Mr cool
;
data want;
set have;
if _N_ = 1 then
do;
retain patternID;
pattern = "/(?<!previous\s)pos\w+ (for)?(by)?\s?(the)?\s?(modi|hod|mht)/i";
patternID = prxparse(pattern);
end;
if prxmatch(patternID,string) > 0 then
hodge_id = 1;
else hodge_id =0;
drop pattern patternid;
run;

https://stackoverflow.com/questions/54374475
复制相似问题