plint

French poetry validator (local mirror of https://gitlab.com/a3nm/plint)
git clone https://a3nm.net/git/plint/
Log | Files | Refs | README

nature.py (498B)


      1 import os
      2 
      3 
      4 def nature_count(x):
      5     # for uppercased words, only one occurrence should be allowed
      6     if x.lower() != x:
      7         return 1
      8     try:
      9         return count[x]
     10     except KeyError:
     11         # return a reasonable overapproximation
     12         return 9
     13 
     14 
     15 count = {}
     16 
     17 f = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/occurrences'))
     18 
     19 while True:
     20     line = f.readline()
     21     if not line:
     22         break
     23     line = line.rstrip().split(' ')
     24     count[line[0]] = int(line[1])