Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from whoosh import fields, index
- import os.path
- import csv
- import codecs
- # This list associates a name with each position in a row
- columns = ["juza","chapter","verse","analysis"]
- schema = fields.Schema(juza=fields.NUMERIC,
- chapter=fields.NUMERIC,
- verse=fields.NUMERIC,
- analysis=fields.KEYWORD)
- # Create the Whoosh index
- indexname = "index"
- if not os.path.exists(indexname):
- os.mkdir(indexname)
- ix = index.create_in(indexname, schema)
- # Open a writer for the index
- with ix.writer() as writer:
- # Open the CSV file
- with codecs.open("yom.csv", "rb","utf8") as csvfile:
- for line in csvfile:
- juza , chapter, verse , analysis = line.split(' ', 3)
- doc = {k:v.strip() for k,v in zip(columns, analysis.split(':'))}
- # Pass the dictionary to the add_document method
- writer.add_document(**doc)
- writer.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement