-
Notifications
You must be signed in to change notification settings - Fork 43
Documentation
quadrismegistus edited this page Apr 22, 2011
·
18 revisions
cd prosodic
python prosodic.py
cd prosodic
python
import prosodic as p
import prosodic as p
t = p.Text('/absolute/path/here.txt') # open path from root
t = p.Text('relative/path/here.txt') # open path relative to directory from which Prosodic initiated
t = p.Text('direct text/with lines//and even/new stanzas') # create texts on the fly
import prosodic as p
p.lang='fi' # method 1: change the lang attribute of the prosodic module
t = p.Text('corpora/a_finnish.txt')
t = p.Text('corpora/an_english.txt',lang='en') # method 2: set the lang='xx' flag on a Text
w = p.Word('transparency',lang='en') # ... or word
import prosodic as p
print p.config # shows the current state of the 'config' dictionary
p.config['print_to_screen']=0 # turn off printing
x.less() # shows just attributes
x.more() # shows attributes and un-inherited methods
x.dir() # shows attributes and all methods callable from this object
help(x) # brings you to Python's interactive help screen showing x's documentation
method 1: by returning a list of a specific entity
x.texts() # returns a list of Texts
x.stanzas() # returns a list of Stanzas
x.lines() # returns a list of Lines
x.words() # returns a list of Words
x.syllables() # returns a list of Syllables
x.syllableBodies() # returns a list of SyllableBodies
x.onsets() # returns a list of Onsets
x.rimes() # returns a list of Rimes
x.nuclei() # returns a list of Nuclei
x.codae() # returns a list of Codae
x.phonemes() # returns a list of Phonemes
x.ents('Word') # returns a list of Words
x.ents('Word',flattenList=False) # returns a list of (list of [differently stressed, weighted, etc] Words)s
x.ents('Word',False) # returns a list of (list of [differently stressed, weighted, etc] Words)s
method 2: using x.children and x.descendants()
import prosodic as p
t = p.Text('Q: if i am a text/to what/do I give birth?')
t.children # A: stanzas
t.descendants() # A: stanzas
# the only difference is .children could be a list of lists [if the .children of a Line]
# -- eg, a line's .children could be: [ ['in.to, in.'to], [the], [woods] ]
# BUT .descendants() always make sure the list is 'flat' (ie, not made of lists)
# directly
for w in t.words():
if len(w.syllables())>1:
print w
# indirectly
new_list = [w for w in t.words() if len(w.syllables())>1]
print new_list
w=p.Word('vocalize') # (create word)
s1=w.syllables()[0] # (get first syllable)
s1.feature() # return dictionary of all features
s1.feature('prom.stress') # return value of this feature if found
w.feature('voice') # did not find feature here; returns nothing
w.feature('voice',searchforit=True) # returns: [(v, True), (k, False), (l, True), (z, True)]
w.feature('voice',True) # same as above
w.feature('+voice',True) # returns: [v, l, z]
w.feature('-voice',True) # returns: [k]
def is_allCV(word): # returns True if each of word's syllables has shape 'CV'
sylls=word.syllables()
shapes=[syll.getShape() for syll in sylls]
for shape in shapes:
if shape!="CV":
return False
return True # this point reached only if not yet returned False b/c (shape!=CV)
t=p.Text('mieleni minun tekevi')
cv_words = [ w for w in t.words() if is_allCV(w) ]
print cv_words # returns: [<Word.tekevi> ['te.ke.vi]]