Zadanie nr 3 - Porownanie dokumentow pod
Transkrypt
Zadanie nr 3 - Porownanie dokumentow pod
Eksploracja danych w internecie (Web-mining) Zadanie nr 3. Porównanie dokumentów. © dr hab. Szymon Grabowski [email protected] © mgr inż. Maciej Łaski [email protected] 1. Przygotowanie danych Dane wejściowe dla zaimplementowanych algorytmów należy uzyskać za pomocą programu zaimplementowanego na pierwszych zajęciach. W pliku na stronie są również większe kawałki tekstu. Należy je poddać obróbce przez te same procedury usuwania znaczników, znaków przestankowych, itp. 2. Opis zadania Podobieństwo między dokumentami tekstowymi (np. webowymi) mierzy się zwykle jako cosinus kąta między wektorami reprezentującymi te dokumenty. Wektory te mają tyle współrzędnych, ile jest słów w słowniku, tj. ile jest unikalnych słów w całej kolekcji dokumentów. Jedną z najprostszych metod przypisywania wag do „termów” (tj. słów) w obrębie wektora jest term count model, gdzie waga danego słowa to liczba jego wystąpień w danym dokumencie podzielona przez łączną liczbę słów w dokumencie. Przykład (b. prosty): mamy 3 dokumenty: Doc #1: this is a horse Doc #2: she rode a black horse Doc #3: a dog, a dog and two horses Słownik: a, and, black, dog, horse, horses, is, rode, she, this, two Wektor dla dokumentu #1: [1/4, 0, 0, 0, 1/4, 0, 1/4, 0, 0, 1/4, 0] Wektor dla dokumentu #2: [1/5, 0, 1/5, 0, 1/5, 0, 0, 1/5, 1/5, 0, 0] Wektor dla dokumentu #3: [2/7, 1/7, 0, 2/7, 0, 1/7, 0, 0, 0, 0, 1/7] V1 ∗ V2 i jest to liczba z V1 ∗ V2 przedziału 0 (brak jakiegokolwiek podobieństwa) do 1 (pełne podobieństwo, tj. niekoniecznie dokumenty identyczne, ale np. posiadające ten sam zestaw słów, ale być może w innej kolejności, np. „Ala ma kota” i „kota ma Ala”). Cosinus kąta między wektorami V1, V2 określa się wzorem: W zadaniu w ramach testów należy policzyć wektory dla 15 dokumentów z wikipedii, po 5 z kategorii: zoologia, muzyka poważna, informatyka, policzyć cosinusową miarę podobieństwa dla każdej pary, a następnie wypisać 10 par najbardziej do siebie podobnych dokumentów (wraz z wartościami miary podobieństwa) i 10 par najmniej do siebie podobnych dokumentów (również z wartościami miary podobieństwa). Algorytm należy przetestować także na większych tekstach, które używane były na poprzednich laboratoriach. Na wykonanie zadania są przeznaczone 2 godziny laboratoryjne. 3. Sposób zaliczenia Zaliczenie zadania na podstawie rozmowy z prowadzącym o sposobach implementacji i optymalizacji kodu. Do wykonania zadania można użyć dowolnego języka programowania i dowolnej biblioteki wedle uznania i dotychczasowej umiejętności studenta. 4. Przykład Poniższe akapit, wzięty z http://en.wikipedia.org/wiki/CPU_cache jest traktowany jako (cały) dokument (nr 0): The diagram on the right shows two memories. Each location in each memory has a datum (a cache line), which in different designs ranges in size from 8 to 512 bytes. The size of the cache line is usually larger than the size of the usual access requested by a CPU instruction, which ranges from 1 to 16 bytes. Each location in each memory also has an index, which is a unique number used to refer to that location. The index for a location in main memory is called an address. Each location in the cache has a tag that contains the index of the datum in main memory that has been cached. In a CPU's data cache these entries are called cache lines or cache blocks. Poniższe 3 akapity, zaczerpnięte z http://en.wikipedia.org/wiki/Johann_Sebastian_Bach są traktowane jako osobne dokumenty (nr 1, 2, 3): Johann Sebastian Bach (pronounced [jo'han/'jo?han ze'bastjan 'bax]) (31 March 1685 [O.S. 21 March] – 28 July 1750) was a German composer and organist whose sacred and secular works for choir, orchestra, and solo instruments drew together the strands of the Baroque period and brought it to its ultimate maturity.[1] Although he introduced no new forms, he enriched the prevailing German style with a robust contrapuntal technique, an unrivalled control of harmonic and motivic organisation in composition for diverse musical forces, and the adaptation of rhythms and textures from abroad, particularly Italy and France. Revered for their intellectual depth, technical command and artistic beauty, Bach's works include the Brandenburg concertos, the Goldberg Variations, the English Suites, the French Suites, the Partitas, the Well-Tempered Clavier, the Mass in B Minor, the St. Matthew Passion, the St. John Passion, the Magnificat, The Musical Offering, The Art of Fugue, the Sonatas and Partitas for violin solo, the Cello Suites, more than 200 surviving cantatas, and a similar number of organ works, including the celebrated Toccata and Fugue in D Minor. While Bach's fame as an organist was great during his lifetime, he was not particularly well-known as a composer. His adherence to Baroque forms and contrapuntal style was considered "oldfashioned" by his contemporaries, especially late in his career when the musical fashion tended towards Rococo and later Classical styles. A revival of interest and performances of his music began early in the 19th century, and he is now widely considered to be one of the greatest composers in the Western tradition, being included with Ludwig van Beethoven and Johannes Brahms as one of the "three Bs". Oto wartości miary cosinusowej dla tych par dokumentów: 0 1 0.0245903704521 // b. mała wartość, bo Bach ma niewiele wspólnego z procesorami... 0 2 0.0300099424404 // j.w. 0 3 0.0192130139235 // j.w. 1 2 0.33996692133 1 3 0.42414659285 // maksimum dla pary (1, 3) 2 3 0.190704311925 Uwaga: bez wyrzucania stop words, wyniki wyszły dużo bardziej zbliżone: 0 1 0.258924116452 0 2 0.384754087479 0 3 0.325882731786 1 2 0.463556429717 1 3 0.53672340922 2 3 0.445769510621