2013-05-05 23 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" 
相關問題