Module Expr Str ImportFrom alias alias alias alias If BoolOpAnd CompareEq NameLoad Str CompareIs NameLoad NameLoad body Import alias alias Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr Num NameLoad Import alias Assign NameStore Call NameLoad Str Delete NameDel NameDel Import alias ImportFrom alias alias Import alias ImportFrom alias ImportFrom alias ImportFrom alias FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str If CompareEq NameLoad NameLoad body Assign NameStore NameLoad Return Call NameLoad Call NameLoad NameLoad Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad NameLoad body Expr Str Assign NameStore ListLoad If CompareIsNot NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad Call NameLoad AttributeLoad NameLoad attr If CompareIsNot NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad Call NameLoad AttributeLoad NameLoad attr Assign NameStore ListLoad For NameStore Call NameLoad Num Call NameLoad NameLoad body For NameStore Call NameLoad BinOpAdd NameLoad Num Call NameLoad NameLoad body Assign TupleStore NameStore NameStore SubscriptLoad NameLoad Index NameLoad Assign TupleStore NameStore NameStore SubscriptLoad NameLoad Index NameLoad Expr Call NameLoad Call AttributeLoad Str attr NameLoad NameLoad With Call NameLoad NameLoad NameStore body With Call NameLoad NameLoad NameStore body Expr Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad Call NameLoad NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return BinOpDiv Call NameLoad NameLoad NameLoad BinOpMult Call NameLoad NameLoad Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return BinOpDiv Call NameLoad NameLoad NameLoad Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str Assign NameStore Call AttributeLoad NameLoad attr FunctionDef arguments args NameParam defaults body Assign NameStore ListLoad If CompareIsNot NameLoad NameLoad body TryExcept body With Call NameLoad NameLoad NameStore body Assign NameStore ListComp Call AttributeLoad NameLoad attr comprehension NameStore Call AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad body Expr Call NameLoad BinOpAdd Str NameLoad Return NameLoad decorator_list Assign NameStore Call NameLoad AttributeLoad NameLoad attr Assign NameStore Call NameLoad AttributeLoad NameLoad attr For NameStore AttributeLoad NameLoad attr body If Call AttributeLoad NameLoad attr Str NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad orelse Expr Call AttributeLoad NameLoad attr NameLoad If CompareLt BinOpAdd Call NameLoad NameLoad Call NameLoad NameLoad Num body Raise Call NameLoad Str Expr Call NameLoad Call AttributeLoad Str attr Call NameLoad Call NameLoad NameLoad NameLoad Assign NameStore Call NameLoad keyword NameLoad keyword NameLoad For TupleStore NameStore NameStore NameStore NameLoad body Expr Call NameLoad Call AttributeLoad Str attr NameLoad NameLoad NameLoad decorator_list If CompareEq NameLoad Str body Expr Call NameLoad
N/A N/A 
Sample usage as a script::

    $ python similarity.py http://www.stanford.edu/ http://www.berkeley.edu/ http://www.mit.edu/
    Comparing files ['http://www.stanford.edu/', 'http://www.berkeley.edu/', 'http://www.mit.edu/']
    sim(http://www.stanford.edu/,http://www.berkeley.edu/)=0.322771960247
    sim(http://www.stanford.edu/,http://www.mit.edu/)=0.142787018368
    sim(http://www.berkeley.edu/,http://www.mit.edu/)=0.248877629741

 __future__ division absolute_import print_function unicode_literals N/A N/A N/A __name__ __main__ N/A __package__ None N/A N/A sys os N/A parent_dir N/A N/A N/A os path dirname N/A N/A N/A os path dirname N/A N/A N/A os path abspath __file__ N/A N/A N/A N/A sys path insert 0 parent_dir N/A pysimsearch N/A __package__ N/A str pysimsearch N/A sys os N/A argparse itertools chain repeat N/A re N/A doc_reader exceptions * term_vec * measure_similarity N/A N/A file_a file_b sim_func N/A None N/A N/A 
    Returns the textual similarity of term_vec_a and term_vec_b using chosen
    similarity metric
    
    'sim_func' defaults to cosine_sim if not specified
     N/A N/A sim_func None N/A N/A sim_func cosine_sim N/A N/A sim_func N/A term_vec file_a N/A term_vec file_b N/A pairwise_compare N/A N/A filenames urls N/A None None N/A N/A 
    Do a pairwise comparison of all documents specified by ``filenames``
    and ``urls`` and return their pairwise similarities
     N/A input N/A N/A N/A filenames None N/A N/A N/A N/A input extend N/A zip filenames N/A repeat N/A doc_reader get_text_file N/A N/A urls None N/A N/A N/A N/A input extend N/A zip urls N/A repeat N/A doc_reader get_url N/A similarities N/A N/A i N/A range 0 N/A len input N/A N/A j N/A range N/A i 1 N/A len input N/A N/A N/A name_a get_input N/A input N/A i N/A N/A name_b get_input N/A input N/A j N/A N/A print N/A N/A comparing {} and {} format name_a name_b N/A N/A get_input name_a file_a N/A N/A N/A get_input name_b file_b N/A N/A N/A N/A similarities append N/A name_a name_b N/A measure_similarity file_a file_b N/A similarities N/A cosine_sim N/A N/A u v N/A N/A N/A 
    Returns the cosine similarity of u,v: ``<u,v>/(|u||v|)``
    where ``|u|`` is the L2 norm
     N/A N/A N/A dot_product u v N/A N/A l2_norm u N/A l2_norm v N/A jaccard_sim N/A N/A A B N/A N/A N/A 
    Returns the Jaccard similarity of A,B: ``|A \cap B| / |A \cup B|``
    We treat A and B as multi-sets (The Jaccard coefficient is technically
    meant for sets, although it is easily extended to multi-sets)
     N/A N/A N/A mag_intersect A B N/A mag_union A B N/A main N/A N/A N/A N/A N/A Commandline interface for measure pairwise similarities of files N/A parser N/A N/A argparse ArgumentParser description List pairwise similarities of input documents N/A N/A N/A parser add_argument doc nargs * help a document in the comparison list N/A N/A N/A parser add_argument -f --filename_list nargs ? help file containing list of filenames to compare N/A N/A N/A parser add_argument -u --url_list nargs ? help file containing list of urls to compare N/A args N/A N/A parser parse_args get_list N/A N/A input_fname N/A N/A N/A list N/A N/A N/A input_fname None N/A N/A N/A N/A N/A open input_fname input_file N/A N/A list N/A N/A N/A line strip N/A line N/A N/A input_file readlines N/A N/A N/A IOError N/A N/A N/A print N/A Sorry, could not open  input_fname N/A list N/A N/A filenames N/A get_list N/A args filename_list N/A urls N/A get_list N/A args url_list N/A doc N/A args doc N/A N/A N/A N/A re search ^http:// doc N/A N/A N/A N/A urls append doc N/A N/A N/A N/A filenames extend doc N/A N/A N/A N/A len filenames N/A len urls 2 N/A N/A N/A Error Sorry, you must specify at least two documents to compare. N/A N/A print N/A N/A Comparing files {} format N/A list N/A chain filenames urls N/A similarities N/A pairwise_compare filenames filenames urls urls N/A N/A name_a name_b sim similarities N/A N/A N/A print N/A N/A sim({0},{1})={2} format name_a name_b sim N/A N/A N/A __name__ __main__ N/A N/A N/A main