David Stephenson avatar David Stephenson committed e35d20e

2013-07-25 09:54:26

Comments (0)

Files changed (6)

build/lib/sigactor/content.py

                 return True
         return False
 
-    def locate(self, term, forward=False, tag=False):
+    def locate(self, term, forward=False, tag=False, plural=False):
         value = ''
         sentences = self.sentences
         for sentence in sentences:
 
             if term in sentence.clean_words:
                 index = sentence.clean_words.index(term)
-                if(
+                if not forward and self.is_proper(index - 1):
+                    if plural:
+                        value = sentence.read_plural(index - 1, forward=False)
+                    value = sentence.read_element(index - 1, forward=False)
+                elif(
                     len(sentence.clean_words) > index + 1 and
                     sentence.clean_words[index + 1] == 'of' and
                     not forward
                 ):
+                    if plural:
+                        value = sentence.read_plural(index + 2)
                     value = sentence.read_element(index + 2)
-                elif not forward:
-                    value = sentence.read_element(index - 1, False)
                 else:
+                    if plural:
+                        value = sentence.read_plural(index + 1)
                     value = sentence.read_element(index + 1)
             if tag:
                 if value:
         while True:
             if len(self.words) > index >= 0:
                 if self.is_proper(index):
-                    terms.append(self.words[index])
+                    term = self.words[index]
+                    if term[-1] == ',':
+                        term = term[:-1]
+                    terms.append(term)
                 else:
                     break
             else:
             element = element[:-1]
 
         return element
+
+    def read_plural(self, index, forward=True):
+        locations = []
+        if self.words[index + 1] == 'of':
+            while True:
+                index = self.words[index + 2]
+
+                if self.is_proper(index):
+                    bounds = self.read_plural_element(index)
+                elif(
+                    self.words[index + 1] == 'and' and
+                    self.is_proper(index + 2)
+                ):
+                    bounds = self.read_plural_element(index + 2)
+
+                locations += bounds
+                index = bounds[1] + 1
+
+    def read_plural_element(self, index):
+        start = index
+        while True:
+            word = self.words[index]
+            if self.is_proper(word):
+                if word[-1] == ',':
+                    break
+            else:
+                break
+            index += 1
+        return [start, index]

build/lib/sigactor/home.py

 
 class Home():
     def __init__(self):
+        self.version = '0.1.17dev'
+
         print(
-            '\nWelcome to SIGACTor 0.1.16dev, currently available '
+            '\nWelcome to SIGACTor ' + self.version + ', currently available '
             'for the Syria team and reading posts from the '
             "Syrian Observatory for Human Rights' Facebook Page."
         )
             'Air',
             'Targeted',
             'Tactical',
+            'Pro-regime KIA',
+            'Pro-regime WIA',
+            'Anti-regime KIA',
+            'Anti-regime WIA',
+            'Total KIA',
+            'Total WIA',
             'Outcome',
             'Full Text',
             'URL',
             'Date Begin',
             'Date End',
             'Posted Date',
+            'Author',
         ]
 
         print('\nPreparing CSV...')
             )
 
             try:
-                self.start_date = datetime.strptime(self.entered_date, '%Y-%m-%d-%H%M%z')
+                self.start_date = datetime.strptime(
+                    self.entered_date, '%Y-%m-%d-%H%M%z'
+                )
                 break
             except ValueError:
                 print('Invalid date. ')

build/lib/sigactor/post.py

 
         self.date = date
         self.now = datetime.now(dateutil.tz.tzlocal())
-        self.timezone_info = self.now.tzinfo
-        self.current_date = self.date.astimezone(self.timezone_info)
-        self.short_date = self.current_date.strftime('%Y-%m-%d')
-        self.time = self.current_date.strftime('%Y-%m-%d-%H%M')
+        self.local_timezone = self.now.tzinfo
+        self.local_date = self.date.astimezone(self.local_timezone)
+        self.short_date = self.local_date.strftime('%Y-%m-%d')
+        self.time = self.local_date.strftime('%Y-%m-%d-%H%M')
 
         self.link = self.item['link']
 
 
         for term in ['reef', 'rif']:
             if self.content.contains(term):
-                self.province = self.content.locate(term, forward=True)
+                self.province = self.content.locate(term)
+
+        if not self.province:
+            sentence = Content(self.content.sentences[0])
+            if sentence.is_proper(0):
+                self.province = sentence.words[0]
 
         self.strategic_terms = [
             'clash',
                     else:
                         self.strategic_sentences.append(sentence.text)
 
+        self.elements = [
+            ['mosque', 'mosques'],
+            ['prison', 'prisons'],
+            ['airport', 'airports'],
+            ['civilian airport', 'civilian airports'],
+            ['military airport', 'military airports'],
+            ['road', 'roads'],
+            ['street', 'streets'],
+            ['highway', 'highways'],
+            ['area', 'areas'],
+            ['neighborhood', 'neighborhoods'],
+            ['neighbourhood', 'neighbourhoods'],
+            ['village', 'villages'],
+            ['suburb', 'suburbs'],
+            ['town', 'towns'],
+            ['city', 'cities'],
+            ['province', 'provinces'],
+        ]
+
+        for sentence in self.strategic_sentences:
+            sentence = Content(sentence)
+
+            for element in self.elements:
+                if sentence.contains(element[1]):
+                    pass
+
         answer = self.layout()
 
         while True:

build/lib/sigactor/property.py

+from getpass import getuser
+
+
 class Property():
     def __init__(self, home, post, activity, name):
         self.home = home
             self.value = ''
 
         if self.name == 'Location':
-            self.elements = [
-                'mosque',
-                'prison',
-                'airport',
-                'civilian airport',
-                'military airport',
-                'road',
-                'street',
-                'highway',
-                'area',
-                'neighborhood',
-                'neighbourhood',
-                'village',
-                'town',
-                'city',
-                'province',
-            ]
-
             self.units = {}
 
-            for number in range(0, len(self.elements)):
+            for number in range(0, len(post.elements)):
+                term = post.elements[number][0]
                 if number <= 7:
-                    self.units[self.elements[number]] = (
+                    self.units[term] = (
                         self.activity.content.locate(
-                            self.elements[number], tag=True
+                            term, tag=True
                         )
                     )
                 else:
-                    self.units[self.elements[number]] = (
-                        self.activity.content.locate(self.elements[number])
+                    self.units[term] = (
+                        self.activity.content.locate(term)
                     )
+                    self.value = self.units[term]
 
             if self.post.province:
                 self.units['province'] = self.post.province
             if self.units['province'].lower() == 'damascus':
                 self.units['province'] = 'Dimashq'
 
-            if not self.units['town']:
+            if not self.units['city']:
                 if self.units['province'] in ['Aleppo', 'Hama', 'Homs']:
-                    self.town = self.post.province
-                    self.y += 'Town determined by province. '
-                if self.units['province'] == 'Raqqah':
-                    self.units['town'] = 'al-Raqqah'
-                    self.y += 'Town determined by province. '
+                    self.units['city'] = self.post.province
+                    self.y += 'City determined by province. '
+                if self.units['city'] == 'Raqqah':
+                    self.units['city'] = 'al-Raqqah'
+                    self.y += 'City determined by province. '
                 if self.units['province'] == 'Dimashq':
-                    self.units['town'] = 'Damascus'
-                    self.y += 'Town determined by province. '
+                    self.units['city'] = 'Damascus'
+                    self.y += 'City determined by province. '
 
             self.units['province'] = 'Rif ' + self.units['province']
 
-            for element in self.elements:
-                if self.units[element].lower() == 'the':
-                    if len(self.post.activities):
-                        self.units[element] = (
+            for element in post.elements:
+                term = element[0]
+                if self.units[term].lower() == 'the':
+                    if self.home.activities:
+                        self.units[term] = (
                             self.post.activities[self.activity.number - 1]
-                            .properties[1].units[element]
+                            .properties[1].units[term]
                         )
+                    else:
+                        self.units[term] = ''
 
-                if self.units[element]:
-                    self.value += self.units[element] + ', '
+                if self.units[term]:
+                    self.value += self.units[term] + ', '
 
             if self.value:
                 if self.value[-2:] == ', ':
         if self.name == 'Blast':
             if self.activity.content.contains('bomb ', 'IED', 'bomber'):
                 self.value = 'IED'
-            if self.activity.content.contains('car bomb ', 'VBIED'):
+            if self.activity.content.contains(
+                'car bomb ', 'VBIED', 'car-bomb'
+            ):
                 self.value = 'VBIED'
             if self.activity.content.contains('suicide'):
                 self.value = 'SVEST'
 
             self.value = self.check(self.value)
 
+            if self.value:
+                self.activity.properties['Orientation'] = 'Anti-Regime'
+
         if self.name == 'Targeted':
             if self.activity.content.contains('execut'):
                 self.value = 'Execution'
 
             self.value = self.check(self.value)
 
+        if self.name == 'Pro-regime KIA':
+            self.value = self.number_check(self.value)
+
+        if self.name == 'Pro-regime WIA':
+            self.value = self.number_check(self.value)
+
+        if self.name == 'Anti-regime KIA':
+            self.value = self.number_check(self.value)
+
+        if self.name == 'Anti-regime WIA':
+            self.value = self.number_check(self.value)
+
+        if self.name == 'Total KIA':
+            self.value = self.number_check(self.value)
+
+        if self.name == 'Total WIA':
+            self.value = self.number_check(self.value)
+
         if self.name == 'Outcome':
             if self.activity.properties['Blast'].value:
                 self.value = 'Effective'
         if self.name == 'Posted Date':
             self.value = self.post.time
 
-    def check(self, value):
+        if self.name == 'Author':
+            self.value = (
+                getuser() + ' via SIGACTor ' + self.home.version + ' at ' +
+                self.post.now.strftime('%Y-%m-%d-%H%M')
+            )
 
+    def check(self, value):
         while True:
             answer = input(
                 '\nContent:\n' + self.activity.content.text + '\n' +
                 return ''
             else:
                 return answer
+
+    def number_check(self, value):
+        while True:
+            answer = self.check(value)
+            if answer:
+                try:
+                    self.value_number = int(answer)
+                    return answer
+                except ValueError:
+                    print('\nInvalid answer. Please enter a number. ')
+                    continue
+            else:
+                return answer
 
 setup(
     name='SIGACTor',
-    version='0.1.16dev',
+    version='0.1.17dev',
     description=open('README.txt').read(),
     url='http://bitbucket.org/davidystephenson/sigactor',
     author='David Y. Stephenson',
 
 class Home():
     def __init__(self):
-        self.version = '0.1.16dev'
+        self.version = '0.1.17dev'
 
         print(
             '\nWelcome to SIGACTor ' + self.version + ', currently available '
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.