#!/usr/bin/python # -*- coding: iso8859-1 -*- #### WAS: -*- coding: utf8 -*- # # wordref_extract.py -- Simple program to extract some # conjugation information out of pages like: # http://www.wordreference.com/conj/ESverbs.asp?v=arg%FCir # # to be tested against the output of Finite State Tools. # # Usage: # from wordref_extract import * # # extract('*.html') # (for example...) # Written April 11 2008 by Antti Karttunen and placed in Public Domain. # Following lines contains the stuff we are interested about: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # And print the extracted words out like this, in this order: # # amar+V+Ger amando # amar+V+Inf amar # amar+V+Pres+Osg+P1 amo # amar+V+Pres+Osg+P2 amas # amar+V+Pres+Osg+P3 ama # amar+V+Pres+Plu+P1 amamos # amar+V+Pres+Plu+P2 amáis # amar+V+Pres+Plu+P3 aman # amar+V+Pret+Osg+P1 amé # amar+V+Pret+Osg+P2 amaste # amar+V+Pret+Osg+P3 amó # amar+V+Pret+Plu+P1 amamos # amar+V+Pret+Plu+P2 amasteis # amar+V+Pret+Plu+P3 amaron # # import os import re def listdir_by_pattern(path,filepattern): '''List all files matching with "filepattern" in the directory "path".''' filepattern = filepattern.replace('*','.*') + '$' filepat = re.compile(filepattern) olddir = os.getcwd() os.chdir(path) allfiles = os.listdir('.') files = filter(lambda(fn): filepat.match(fn),allfiles) os.chdir(olddir) return(files) def wordref_extract_aux(filename): '''Opens file "filename" for reading and scans some information from it.''' infp = open(filename,'r') person_et_number = ['+Osg+P1','+Osg+P2','+Osg+P3', '+Plu+P1','+Plu+P2','+Plu+P3'] next_infinitivo_et_gerundio = False indicative_mood = False indicativo_presente_despues_n_lineas = 0 indicativo_preterito_despues_n_lineas = 0 anyspaceandtagspat = re.compile(r'\s*<[^>]*>\s*') boldtagspat = re.compile(r'') trigger_pat_inf_et_ger = re.compile(r'.*Infinitivo:.*Gerundio:.*') trigger_pat_indicativo = re.compile(r'.*Indicativo.*') trigger_pat_compuestos = re.compile(r'.*Tiempos compuestos.*') trigger_pat_subjuntivo = re.compile(r'.*Subjuntivo.*') trigger_pat_imperativo = re.compile(r'.*Imperativo.*') trigger_pat_presente = re.compile(r'.*presente.*') trigger_pat_imperfecto = re.compile(r'.*imperfecto.*') trigger_pat_preterito = re.compile(r'.*pretérito.*') for line in infp: # print "Line before sub-operation:\n" + line line = boldtagspat.sub('', line) # Eradicate all and tags at once. # print "Line after sub-operation:\n" + line if(trigger_pat_inf_et_ger.match(line)): next_infinitivo_et_gerundio = True # print "The next is it, line is now:\n" + line elif(next_infinitivo_et_gerundio): next_infinitivo_et_gerundio = False; words = anyspaceandtagspat.split(line) words = [x for x in words if x != ''] # Delete blankos. infinitivo = words[0]; gerundio = words[1]; print '%-24s %s' % ((infinitivo + "+V+Ger"),gerundio) print '%-24s %s' % ((infinitivo + "+V+Inf"),infinitivo) elif(trigger_pat_indicativo.match(line)): indicative_mood = True elif(trigger_pat_compuestos.match(line) or trigger_pat_subjuntivo.match(line) or trigger_pat_imperativo.match(line)): indicative_mood = False elif(indicative_mood): if(trigger_pat_presente.match(line)): indicativo_presente_despues_n_lineas = 9; if(trigger_pat_preterito.match(line)): indicativo_preterito_despues_n_lineas = 9; if(0 != indicativo_presente_despues_n_lineas): indicativo_presente_despues_n_lineas -= 1 if(0 == indicativo_presente_despues_n_lineas): words = anyspaceandtagspat.split(line) words = [x for x in words if x != ''] # Delete blankos. print_finite_forms(infinitivo,'+Pres',person_et_number,words) if(0 != indicativo_preterito_despues_n_lineas): indicativo_preterito_despues_n_lineas -= 1 if(0 == indicativo_preterito_despues_n_lineas): words = anyspaceandtagspat.split(line) words = [x for x in words if x != ''] # Delete blankos. print_finite_forms(infinitivo,'+Pret',person_et_number,words) else: # Do nothing so far. next_infinitivo_et_gerundio = False; def print_finite_forms(infinitivo,mood,person_et_number,forms): '''Print some of the finite conjugations of verb "infinitivo" in mood "mood".''' for i in range(len(forms)): word = forms[i] pn = person_et_number[i]; print '%-24s %s' % ((infinitivo + "+V" + mood + pn),word) def extract(filepat): '''Opens files specified with "filepat" for reading and extract some information from them.''' files = listdir_by_pattern('.',filepat) for filename in files: wordref_extract_aux(filename) # This module ends here.
Infinitivo:
Gerundio:
Participio:
argüir
arguyendo
# argüido
DefiniciónEn Inglés
# En Francés
# En Portugués
  
Indicativo
 presenteimperfectopretéritofuturocondicional
yo

él, ella, Ud.
nosotros
vosotros
ellos, ellas, Uds.
arguyo
arguyes
arguye
argüimos
argüís
arguyen
argüía
argüías
argüía
argüíamos
argüíais
argüían
argüí
argüiste
arguyó
argüimos
argüisteis
arguyeron
argüiré
argüirás
argüirá
argüiremos
argüiréis
argüirán
argüiría
argüirías
argüiría
argüiríamos
argüiríais
argüirían