ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Tree-M/MT/MTobject.cpp
Revision: 1.1
Committed: Sun May 6 00:45:52 2001 UTC (23 years, 1 month ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /*********************************************************************
2     * *
3     * Copyright (c) 1997,1998, 1999 *
4     * Multimedia DB Group and DEIS - CSITE-CNR, *
5     * University of Bologna, Bologna, ITALY. *
6     * *
7     * All Rights Reserved. *
8     * *
9     * Permission to use, copy, and distribute this software and its *
10     * documentation for NON-COMMERCIAL purposes and without fee is *
11     * hereby granted provided that this copyright notice appears in *
12     * all copies. *
13     * *
14     * THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE *
15     * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING *
16     * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, *
17     * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR *
18     * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A *
19     * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS *
20     * DERIVATIVES. *
21     * *
22     *********************************************************************/
23    
24     #include <stdio.h>
25     #include "MTobject.h"
26    
27     //double W[9]={1, 2, 1, 2, 4, 2, 2, 4, 2};
28    
29     /*
30     int
31     Object::CompressedLength() const
32     {
33     return(sizeof(int)+tot_term*(sizeof(float)+sizeof(int)));
34     }
35    
36     int
37     Object::operator==(const Object &obj)
38     {
39     Term_Weight *m=obj.lst_tw, *n=lst_tw;
40    
41     while(n&&m) {
42     if((n->id_term)!=(m->id_term)) return 0;
43     if((n->weight)!=(m->weight)) return 0;
44     n=n->next;
45     m=m->next;
46     }
47     if(n||m) return 0;
48     return 1;
49     }
50    
51     double
52     Object::distance(const Object& other) const
53     {
54     double dist=0.0;
55     double s=0, r=0, t=0, sim;
56     Term_Weight *m=other.lst_tw, *n=lst_tw;
57    
58     compdists++;
59     while(m&&n) {
60     if(m->id_term==n->id_term) {
61     s=s+(m->weight*n->weight);
62     r=r+pow(m->weight, 2);
63     t=t+pow(n->weight, 2);
64     m=m->next;
65     n=n->next;
66     }
67     else if(m->id_term<n->id_term) {
68     r=r+pow(m->weight, 2);
69     m=m->next;
70     }
71     else {
72     t=t+pow(n->weight, 2);
73     n=n->next;
74     }
75     }
76     while(m) {
77     r=r+pow(m->weight, 2);
78     m=m->next;
79     }
80     while(n) {
81     t=t+pow(n->weight, 2);
82     n=n->next;
83     }
84     sim=s/sqrt(r*t);
85     dist=sqrt(2*(1-sim));
86     return dist;
87     }
88    
89     Object *Read()
90     {
91     char cmdLine[1024];
92     int totTerm;
93     Term_Weight *head, **tail=&head, *next;
94    
95     // scanf("%s", cmdLine);
96     scanf("%s", cmdLine);
97     totTerm=atoi(cmdLine);
98     for(int i=0; i<totTerm; i++) {
99     Term_Weight *node=new Term_Weight;
100    
101     scanf("%s", cmdLine);
102     node->id_term=atoi(cmdLine);
103     scanf("%s", cmdLine);
104     node->weight=atof(cmdLine);
105     *tail=node;
106     tail=&(node->next);
107     }
108     *tail=NULL;
109     Object *obj=new Object(head);
110    
111     for(Term_Weight *node=head; node; node=next) {
112     next=node->next;
113     delete node;
114     }
115     return obj;
116     }
117    
118     Object *Read(FILE *fp)
119     {
120     char cmdLine[1024];
121     int totTerm;
122     Term_Weight *head, **tail=&head, *next;
123    
124     // fscanf(fp, "%s", cmdLine);
125     fscanf(fp, "%s", cmdLine);
126     totTerm=atoi(cmdLine);
127     for(int i=0; i<totTerm; i++) {
128     Term_Weight *node=new Term_Weight;
129    
130     fscanf(fp, "%s", cmdLine);
131     node->id_term=atoi(cmdLine);
132     fscanf(fp, "%s", cmdLine);
133     node->weight=atof(cmdLine);
134     *tail=node;
135     tail=&(node->next);
136     }
137     *tail=NULL;
138     Object *obj=new Object(head);
139    
140     for(Term_Weight *node=head; node; node=next) {
141     next=node->next;
142     delete node;
143     }
144     return obj;
145     }
146    
147     int sizeofObject()
148     {
149     return 0; // objects of different sizes
150     }
151    
152     double maxDist()
153     {
154     return sqrt(2);
155     }
156    
157     #ifdef PRINTING_OBJECTS
158     void
159     Object::Print(ostream& os) const
160     {
161     os << "(";
162     for(Term_Weight *p=lst_tw; p; p=p->next) {
163     os << p->id_term;
164     os << ": " << p->weight << ", ";
165     }
166     os << ")";
167     }
168     #endif
169     */
170