def pruneMarks(markup): """ prune Marked objects by deleting any objects that lie within the span of another object. Currently modifiers and targets are treated separately """ markupNew = markup.copy() marks = markupNew.nodes(data=True) if( len(marks) < 2 ): return markupNew marks.sort() nodesToRemove = [] for i in range(len(marks)-1): if( marks[i][0] not in nodesToRemove ): for j in range(i+1,len(marks)): if( TO.encompasses(marks[i][0],marks[j][0]) and marks[i][1]['category'] == marks[j][1]['category'] ): nodesToRemove.append(marks[j][0]) elif( TO.encompasses(marks[j][0],marks[i][0]) and marks[i][1]['category'] == marks[j][1]['category'] ): nodesToRemove.append(marks[i][0]) break if( markupNew.getVerbose() ): print u"pruning the following nodes" for n in nodesToRemove: print n markupNew.remove_nodes_from(nodesToRemove) return markupNew
def pruneMarks(markup): """ prune Marked objects by deleting any objects that lie within the span of another object. Currently modifiers and targets are treated separately """ markupNew = markup.copy() marks = markupNew.nodes(data=True) if (len(marks) < 2): return markupNew marks.sort() nodesToRemove = [] for i in range(len(marks) - 1): if (marks[i][0] not in nodesToRemove): for j in range(i + 1, len(marks)): if (TO.encompasses(marks[i][0], marks[j][0]) and marks[i][1]['category'] == marks[j][1]['category']): nodesToRemove.append(marks[j][0]) elif (TO.encompasses(marks[j][0], marks[i][0]) and marks[i][1]['category'] == marks[j][1]['category']): nodesToRemove.append(marks[i][0]) break if (markupNew.getVerbose()): print u"pruning the following nodes" for n in nodesToRemove: print n markupNew.remove_nodes_from(nodesToRemove) return markupNew
def pruneSelfModifyingRelationships(markup): """ We make sure that there are no self modifying modifiers present (e.g. "free" in the phrase "free air" modifying the target "free air"). modifiers = self.getConTextModeNodes("modifier") """ markupNew = markup.copy() modifiers = markup.getConTextModeNodes("modifier") nodesToRemove = [] for m in modifiers: modifiedBy = markup.successors(m) if( modifiedBy ): for mb in modifiedBy: if( TO.encompasses(mb,m) ): nodesToRemove.append(m) markupNew.remove_nodes_from(nodesToRemove) return markupNew
def pruneSelfModifyingRelationships(markup): """ We make sure that there are no self modifying modifiers present (e.g. "free" in the phrase "free air" modifying the target "free air"). modifiers = self.getConTextModeNodes("modifier") """ markupNew = markup.copy() modifiers = markup.getConTextModeNodes("modifier") nodesToRemove = [] for m in modifiers: modifiedBy = markup.successors(m) if (modifiedBy): for mb in modifiedBy: if (TO.encompasses(mb, m)): nodesToRemove.append(m) markupNew.remove_nodes_from(nodesToRemove) return markupNew