3 Vector Space Model (VSM) is an algebraic model for representing text documents
4 (and any objects, in general) as vectors of identifiers, such as, for example,
7 It is used in information filtering, information retrieval, indexing and
10 The `vsm` package provides the following features:
11 * Vector comparison with cosine similarity.
12 * Vector indexing and matching with tf * idf.
13 * File indexing and matching to free text queries.
17 With VSM, documents are represented by a n-dimensions vector.
18 Each dimension represent an attribute of the document or object.
20 For text document, the count of each term found in the document if often used to
26 var vector = new Vector
29 assert vector["term1"] == 2.0
30 assert vector["term2"] == 1.0
31 assert vector.norm.is_approx(2.236, 0.001)
45 var query = new Vector
48 var s1 = query.cosine_similarity(v1)
49 var s2 = query.cosine_similarity(v2)
55 VSMIndex is a Document index based on VSM.
57 Using VSMIndex you can index documents associated with their vector.
58 Documents can then be matched to query vectors.
60 This represents a minimalistic search engine.
63 var index = new VSMIndex
65 var d1 = new Document("Doc 1", "/uri/1", v1)
66 index.index_document(d1)
68 var d2 = new Document("Doc 2", "/uri/2", v2)
69 index.index_document(d2)
71 assert index.documents.length == 2
76 var matches = index.match_vector(query)
77 assert matches.first.document == d1
82 The StringIndex provides usefull services to index and match strings.
85 index = new StringIndex
87 d1 = index.index_string("Doc 1", "/uri/1", "this is a sample")
88 d2 = index.index_string("Doc 2", "/uri/2", "this and this is another example")
89 assert index.documents.length == 2
91 matches = index.match_string("this sample")
92 assert matches.first.document == d1
97 The FileIndex is a StringIndex able to index and retrieve files.
100 index = new FileIndex
102 index.index_files(["/path/to/doc/1", "/path/to/doc/2"])