示例#1
0
 def __init__(self, sourceCollection=None):
     """Sets the initial state of self, which includes the
     contents of sourceCollection, if it's present."""
     # Uses a circular linked structure with a dummy header node
     self._head = TwoWayNode()
     self._head.previous = self._head.next = self._head
     AbstractList.__init__(self, sourceCollection)
示例#2
0
    def __init__(self, sourceCollection=None):
        """Set the inital state  of self,which include the contents 
		of soureCollection ,if it's present """
        # Use a circular structure with a sential node
        self._head = TwoWayNode()
        self._head.previou = self._head.next = self._head
        AbstractList.__init__(self, sourceCollection)
示例#3
0
 def __init__(self, sourceCollection = None):
     """Sets the initial state of self, which includes the
     contents of sourceCollection, if it's present."""
     # Uses a circular linked structure with a dummy header node
     self._head = TwoWayNode()
     self._head.previous = self._head.next = self._head
     AbstractList.__init__(self, sourceCollection)
示例#4
0
 def __init__(self, source_collection=None):
     """
     Sets the initial state of self, which includes the contents of source_collection, if it's present.
     :param source_collection:
     """
     # Uses a circular structure with a sentinel node
     self.head = TwoWayNode()
     self.head.previous = self.head.next = self.head
     AbstractList.__init__(self, source_collection)
示例#5
0
 def __init__(self, source_collection=None):
     # head 指向哨兵节点, 而不是数据节点,
     self._head = DoubleNode()
     self._head.previous = self._head
     AbstractList.__init__(self, source_collection)
示例#6
0
 def add(self, item):
     """Adds item to self."""
     AbstractList.add(self, item)
示例#7
0
 def index(self, item):
     """Precondition: item is in the list.
     Returns the position of item.
     Raises: ValueError if the item is not in the list."""
     return AbstractList.index(self, item)
示例#8
0
    def __init__(self, sourceCollection=None):
        """Sets the initial state of self, which includes the
        contents of sourceCollection, if it's present."""
        #Uses a circular struture with a sentinel node
        self._head = TwoWayNode()
        self._head.previous = self._head.next = self._head
        AbstractList.__init__(self, sourceCollection)

        # Accessor methods
        def __iter__(self):
            """Supports iteration over a view of self."""
            cursor = self._head.next
            while cursor != self._head:
                yield cursor.data
                cursor = cursor.next

        # Helper method returns node at position i
        def _getNode(self, i):
            """Helper method: returns a pointer to the node
            at positon i."""
            if i == len(self):
                return self._head
            if i == len(self) - 1:
                return self._head.previous
            probe = self._head.next
            while i > 0:
                probe = probe.next
                i -= 1
            return probe

        #Mutator methods
        def __getitem__(self, i):
            """Precondition: 0 <= i < len(self)
            Returns the item at position i."""
            if i < 0 or i >= len(self):
                raise IndexError("List index out of range")
            return self._getNode(i).data

        def __setitem__(self, i, item):
            """Precondition: 0 <= i < len(self)
            Replace the item at position i.
            Raises: IndexError."""
            if i < 0 or i >= len(self):
                raise IndexError("List index out of range")
            self._getNode(i).data = item

        def insert(self, i, item):
            """Inserts the item at position i."""
            if i < 0:
                i = 0
            elif i > len(self):
                i = len(self)
            theNode = self._getNode(i)
            newNode = TwoWayNode(item, theNode.previous, theNode)
            theNode.previous.next = newNode
            theNode.previous = newNode
            self._size += 1
            self.incModCount()

        def pop(self, i=None):
            """Precondition: 0 <= i < len(self)
            Removes and returns the item at position i.
            If i ins None, i is given a default of len(self) - 1.
            Raises: IndexError."""
            if i == None:
                i = len(self) - 1
            if i < 0 or i >= len(self):
                raise IndexError("List index out of range")
            theNode = self._getNode(i)
            item = theNode.data
            theNode.previous.next = theNode.next
            theNode.next.previous = thenode.previous
            self._size -= 1
            self.incModCount()
            return item
示例#9
0
 def __init__(self, sourceCollection=None):
     self._head = TwoWayNode()
     self._head.prevous = self._head.next = self._head
     AbstractList.__init__(self, sourceCollection)
示例#10
0
#!/usr/bin/python
# author: Rodney Summerscales

import sys
#import nltk
#from nltk.corpus import wordnet as wn

from abstractlist import AbstractList

if len(sys.argv) < 3:
    print "Usage: displayentities.py <ABSTRACT_PATH> <LABEL_1> <LABEL_2> ... <LABEL_N>"
    print "Output the entities with a given label for all of the abstracts in given path."
    sys.exit()

inputPath = sys.argv[1]
absList = AbstractList(inputPath)
labelList = sys.argv[2:]
out = open('abstracts.entities.txt', 'w')

for abstract in absList:
    out.write('---%s---\n' % abstract.id)
    for label in labelList:
        entityList = []
        for sentence in abstract.sentences:
            annotatedEntities = sentence.getAnnotatedMentions(label)
            if len(annotatedEntities) > 0:
                entityList += annotatedEntities
        if len(entityList) > 0:
            out.write('%s:\n' % label)
            for m in entityList:
                out.write('\t%s\n' % m.text)
示例#11
0
 def __init__(self, sourceCollection=None):
     """Sets the initial state of self, which includes the
     contents of sourceCollection, if it's present."""
     self._items = Array(ArrayList.DEFAULT_CAPACITY)
     AbstractList.__init__(self, sourceCollection)
示例#12
0
 def add(self, item):
     AbstractList.add(self, item)
 def __init__(self, source_collection=None):
     self._items = Array(ArrayList.DEFAULT_CAPACITY)
     AbstractList.__init__(self, source_collection)
示例#14
0
 def __init__(self, sourceCollection = None):
     """Sets the initial state of self, which includes the
     contents of sourceCollection, if it's present."""
     self._items = Array(ArrayList.DEFAULT_CAPACITY)
     AbstractList.__init__(self, sourceCollection)
示例#15
0
 def add(self, item):
     """Adds item to self."""
     AbstractList.add(self, item)
示例#16
0
 def index(self, item):
     """Precondition: item is in the list.
     Returns the position of item.
     Raises: ValueError if the item is not in the list."""
     return AbstractList.index(self, item)