1
我想幹這個代碼。我似乎無法弄清楚如何。如何幹這個紅寶石代碼
def get_all_verb_nodes
all_verb_nodes = @all_nodes_ins_del_nodes.select { |node|
previous_node = node.xpath('preceding-sibling::w:r').last
base_word = previous_node.text.split.last.strip.delete('.!?,:') if previous_node
words = get_node_text(node)
next_node = node.next_element
next_node_is_insert_or_delete = is_insert_or_delete?(next_node.name) if next_node
next_node_word = next_node.text.strip if next_node
words.length <= 2 && words.any? { |word| is_a_verb?(base_word+word) || is_a_verb?(word) && !is_pluralized?(base_word+word, base_word+next_node_word) } && !next_node_is_insert_or_delete
}
end
def get_all_article_nodes
all_article_nodes = @all_nodes_ins_del_nodes.select { |node|
previous_node = node.xpath('preceding-sibling::w:r').last
base_word = previous_node.text.split.last.strip.delete('.!?,:') if previous_node
words = get_node_text(node)
next_node = node.next_element
next_node_is_insert_or_delete = is_insert_or_delete?(next_node.name) if next_node
next_node_word = next_node.text.strip if next_node
words.length <= 2 && words.any? { |word| @articleset.include?(word) || (@articleset.include?(base_word) if word == 'n') } && [email protected]?(next_node_word) && !next_node_is_insert_or_delete
}
end
兩者幾乎相同,只是最後一行定義了函數的具體要求。
任何想法讚賞。
它看起來相當程序化,很難閱讀評論,但塊和調用'yield'可能是你在這裏需要的。 –