2013-05-05 63 views
0

我有一个由文本生成的单词列表。该清单包括专有名称(例如John,Mary,Edinburgh)。在另一个领域,我有一个专名的名单。我想获得没有正确名称的所有单词形式的列表。如何从另一个列表中删除一个列表中的单词(设置操作)

我确实需要 allWordForms MINUS properNames

阵列可以使用的套装。但我们只有设置操作UnionIntersect

剧本至今

on mouseUp 
    put field "allWordForms" into tWordForms 
    split tWordForms by return 
    -- tWordForms is now an array 

    put field "properNames" into tProperNames 
    split tProperNames by return 
    -- tProperNames is now an array 

    -- ..... 
    repeat 
    -- ..... 
    -- ..... 
    end repeat 

    combine tWordForms using return 

    put tWordForms into field "wordFormsWithoutProperNames" 

end mouseUp 

如何重复回路样子?

这里是一个例子。

字段 “allWordForms” 包含

Mary 
and 
John 
came 
yesterday 
They 
want 
to 
move 
from 
Maryland 
to 
Petersbourough 

`

字段 “properNames” 包含

John 
Mary 
Maryland 
Peter 
Petersbourough 

期望的结果是有名单allWordForms的副本与适当的名称已删除。

and 
came 
yesterday 
They 
want 
to 
move 
from 
to 

回答

1

这是一个可能的解决方案;

on mouseUp 
    put field "allWordForms" into tWordForms 
    put field "properNames" into tProperNames 

    # replace proper names 
    repeat for each line tProperName in tProperNames 
     replace tProperName with empty in tWordForms 
    end repeat 

    # remove blank lines 
    replace LF & LF with LF in tWordForms 

    put tWordForms into field "wordFormsWithoutProperNames" 
end mouseUp 

另一个解决方案考虑到您的额外信息;

on mouseUp 
    put field "allWordForms" & LF into tWordForms 
    put field "properNames" into tProperNames 

    repeat for each line tProperName in tProperNames 
     replace tProperName & LF with empty in tWordForms 
    end repeat 

    put tWordForms into field "wordFormsWithoutProperNames" 
end mouseUp 
+0

我添加了一个示例的问题。您的解决方案提供了为产生以下字符串(包括开头空单)'和 昨天 来到他们 要从 到 移动 土地 到 sbourough'。 “马里兰”和“彼得斯堡”这两个词被切碎,这不是预期的结果。我想确保它与整个字形一起工作。这就是为什么我要求重复循环,并建议去阵列。数组支持set操作'Union'和'Intersect'。我正在寻找实现'tAllWordForms minus tProperNames'的livecode语法。 – 2013-05-05 13:25:55

+0

没有内置数组功能来实现您的目标,但第二个示例按照您的数据的要求工作。 – splash21 2013-05-05 17:35:30

+0

注意:第一种解决方案不能可靠地工作。 – 2013-05-06 04:17:25

0

可以使用滤波器容器而不图案功能:

put field "allWordsForms" into tResult 
repeat for each line aLine in field "ProperNames" 
    filter tResult without aLine 
end repeat 
put tResult into field "wordFormsWithoutProperNames" 
相关问题