Merge lp:~zeitgeist/zeitgeist/fix-592599-subject-AND into lp:zeitgeist/0.1

Proposed by Markus Korn
Status: Merged
Merged at revision: 1526
Proposed branch: lp:~zeitgeist/zeitgeist/fix-592599-subject-AND
Merge into: lp:zeitgeist/0.1
Diff against target: 167 lines (+63/-46)
3 files modified
_zeitgeist/engine/main.py (+47/-39)
test/engine-test.py (+12/-1)
test/remote-test.py (+4/-6)
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/fix-592599-subject-AND
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen diff and run unit tests Approve
Zeitgeist Framework Team Pending
Review via email: mp+30920@code.launchpad.net

Commit message

Changing the connector of subjects in a query template from OR to AND

Description of the change

This branch changes the connector of subjects in a template from "OR" to "AND", so a template like

 (*event_metadata, [subject1, subject2])

does not expand to

 *event_metadata AND (subject1 or subject2)

anymore, but now it's

 *event_metadata AND subject1 AND subject2

(the connector for the metadata of an event is still AND)

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks good and all the tests are passing on my end. Good work Markus!

review: Approve (diff and run unit tests)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_zeitgeist/engine/main.py'
2--- _zeitgeist/engine/main.py 2010-07-01 08:04:55 +0000
3+++ _zeitgeist/engine/main.py 2010-07-26 09:02:01 +0000
4@@ -214,11 +214,18 @@
5
6 where_or = WhereClause(WhereClause.OR)
7
8- for (event_template, subject_template) in self._build_templates(templates):
9+ for template in templates:
10+ event_template = Event((template[0], [], None))
11+ if template[1]:
12+ subject_templates = [Subject(data) for data in template[1]]
13+ else:
14+ subject_templates = None
15+ # first of all we need to check if the query is supported at all
16 # we do not support searching by storage field for now
17 # see LP: #580364
18- if subject_template[Subject.Storage]:
19- raise ValueError("zeitgeist does not support searching by 'storage' field")
20+ if subject_templates is not None:
21+ if any(data[Subject.Storage] for data in subject_templates):
22+ raise ValueError("zeitgeist does not support searching by 'storage' field")
23
24 subwhere = WhereClause(WhereClause.AND)
25
26@@ -246,50 +253,51 @@
27 if event_manif_where:
28 subwhere.extend(event_manif_where)
29
30- value, negation, wildcard = parse_operators(Subject, Subject.Interpretation, subject_template.interpretation)
31- # Expand subject interpretation children
32- su_interp_where = WhereClause(WhereClause.OR, negation)
33- for child_interp in (Symbol.find_child_uris_extended(value)):
34- if child_interp:
35- su_interp_where.add_text_condition("subj_interpretation",
36- child_interp, like=wildcard, cache=self._interpretation)
37- if su_interp_where:
38- subwhere.extend(su_interp_where)
39-
40- value, negation, wildcard = parse_operators(Subject, Subject.Manifestation, subject_template.manifestation)
41- # Expand subject manifestation children
42- su_manif_where = WhereClause(WhereClause.OR, negation)
43- for child_manif in (Symbol.find_child_uris_extended(value)):
44- if child_manif:
45- su_manif_where.add_text_condition("subj_manifestation",
46- child_manif, like=wildcard, cache=self._manifestation)
47- if su_manif_where:
48- subwhere.extend(su_manif_where)
49-
50- # FIXME: Expand mime children as well.
51- # Right now we only do exact matching for mimetypes
52- # thekorn: this will be fixed when wildcards are supported
53- value, negation, wildcard = parse_operators(Subject, Subject.Mimetype, subject_template.mimetype)
54- if value:
55- subwhere.add_text_condition("subj_mimetype",
56- value, wildcard, negation, cache=self._mimetype)
57-
58 value, negation, wildcard = parse_operators(Event, Event.Actor, event_template.actor)
59 if value:
60 subwhere.add_text_condition("actor", value, wildcard, negation, cache=self._actor)
61+
62+ if subject_templates is not None:
63+ for subject_template in subject_templates:
64+ value, negation, wildcard = parse_operators(Subject, Subject.Interpretation, subject_template.interpretation)
65+ # Expand subject interpretation children
66+ su_interp_where = WhereClause(WhereClause.OR, negation)
67+ for child_interp in (Symbol.find_child_uris_extended(value)):
68+ if child_interp:
69+ su_interp_where.add_text_condition("subj_interpretation",
70+ child_interp, like=wildcard, cache=self._interpretation)
71+ if su_interp_where:
72+ subwhere.extend(su_interp_where)
73+
74+ value, negation, wildcard = parse_operators(Subject, Subject.Manifestation, subject_template.manifestation)
75+ # Expand subject manifestation children
76+ su_manif_where = WhereClause(WhereClause.OR, negation)
77+ for child_manif in (Symbol.find_child_uris_extended(value)):
78+ if child_manif:
79+ su_manif_where.add_text_condition("subj_manifestation",
80+ child_manif, like=wildcard, cache=self._manifestation)
81+ if su_manif_where:
82+ subwhere.extend(su_manif_where)
83+
84+ # FIXME: Expand mime children as well.
85+ # Right now we only do exact matching for mimetypes
86+ # thekorn: this will be fixed when wildcards are supported
87+ value, negation, wildcard = parse_operators(Subject, Subject.Mimetype, subject_template.mimetype)
88+ if value:
89+ subwhere.add_text_condition("subj_mimetype",
90+ value, wildcard, negation, cache=self._mimetype)
91+
92+ for key in ("uri", "origin", "text"):
93+ value = getattr(subject_template, key)
94+ if value:
95+ value, negation, wildcard = parse_operators(Subject, getattr(Subject, key.title()), value)
96+ subwhere.add_text_condition("subj_%s" %key, value, wildcard, negation)
97 except KeyError, e:
98 # Value not in DB
99 log.debug("Unknown entity in query: %s" % e)
100 where_or.register_no_result()
101 continue
102-
103- for key in ("uri", "origin", "text"):
104- value = getattr(subject_template, key)
105- if value:
106- value, negation, wildcard = parse_operators(Subject, getattr(Subject, key.title()), value)
107- subwhere.add_text_condition("subj_%s" %key, value, wildcard, negation)
108- where_or.extend(subwhere)
109-
110+ where_or.extend(subwhere)
111 return where_or
112
113 def _build_sql_event_filter(self, time_range, templates, storage_state):
114
115=== modified file 'test/engine-test.py'
116--- test/engine-test.py 2010-07-22 09:19:02 +0000
117+++ test/engine-test.py 2010-07-26 09:02:01 +0000
118@@ -402,7 +402,18 @@
119 StorageState.Any,
120 100,
121 0,)
122- self.assertEquals(2, len(result))
123+ self.assertEquals(0, len(result)) # no subject with two different
124+ # interpretations at the same time
125+ subj = Subject.new_for_values(uri="file:///tmp/foo.txt")
126+ subj1 = Subject.new_for_values(interpretation="stfu:Image")
127+ event_template = Event.new_for_values(subjects=[subj, subj1])
128+ result = self.engine.find_eventids(
129+ (0, 200),
130+ [event_template, ],
131+ StorageState.Any,
132+ 100,
133+ 0,)
134+ self.assertEquals(1, len(result))
135
136 def testJsonImport(self):
137 import_events("test/data/single_event.js", self.engine)
138
139=== modified file 'test/remote-test.py'
140--- test/remote-test.py 2010-07-14 13:16:59 +0000
141+++ test/remote-test.py 2010-07-26 09:02:01 +0000
142@@ -87,21 +87,19 @@
143 self.assertEquals("Boogaloo", event.actor)
144
145 # Search for everything
146- import dbus
147- ids = self.findEventIdsAndWait([], num_events=3) # dbus.Array(signature="(asaasay)")
148+ ids = self.findEventIdsAndWait([], num_events=3)
149 self.assertEquals(3, len(ids)) # (we can not trust the ids because we don't have a clean test environment)
150
151 # Search for some specific templates
152- subj_templ1 = Subject.new_for_values(uri="foo://bar")
153- subj_templ2 = Subject.new_for_values(uri="foo://baz")
154+ subj_templ1 = Subject.new_for_values(manifestation=Manifestation.FILE_DATA_OBJECT)
155+ subj_templ2 = Subject.new_for_values(interpretation=Interpretation.IMAGE)
156 event_template = Event.new_for_values(
157 actor="Boogaloo",
158 interpretation=Interpretation.ACCESS_EVENT,
159 subjects=[subj_templ1,subj_templ2])
160 ids = self.findEventIdsAndWait([event_template],
161 num_events=10)
162- logging.debug("RESULTS %s" %map(int, ids))
163- self.assertEquals(2, len(ids))
164+ self.assertEquals(1, len(ids))
165
166 def testUnicodeInsert(self):
167 events = parse_events("test/data/unicode_event.js")

Subscribers

People subscribed via source and target branches