Project

General

Profile

« Previous | Next » 

Revision d9380ab9

Added by dsorber almost 12 years ago

Adding a new project the term frequency simulator which will be used to simulate our term freqeuncy approach and measure various statistics.

View differences:

software/term_freq_sim/simulator.py
import sys
from lxml import etree
MEDIA_WIKI_NAMESPACE = 'http://www.mediawiki.org/xml/export-0.8/'
def main():
# Validate the input
if len(sys.argv) < 2:
print '\nERROR: Not enough arguments provided!'
print '\nUSAGE: simulator.py <xml input file>\n'
return -1
# Attempt to open the input file
try:
xml_file = open(sys.argv[1], 'r')
except IOError:
print '\nERROR: unable to open file "{:s}"'.format(sys.argv[1])
return -2
# Parse the input file into an ElementTree
tree = etree.parse(xml_file)
xml_file.close()
root = tree.getroot()
# Get all article titles
# tree.xpath('//w:page/w:title/text()',
# namespaces={'w': 'http://www.mediawiki.org/xml/export-0.8/'})
# Get article text
article_text = tree.xpath('(//w:page/w:revision/w:text/text())[130]',
namespaces={'w': MEDIA_WIKI_NAMESPACE})
# print len(article_text)
# print article_text
word_list = [word for word in article_text[0].split()]
for word in word_list:
print word
if __name__ == '__main__':
sys.exit(main())

Also available in: Unified diff