Skip to content

Commit d97d5aa

Browse files
committed
support for JanusGraph 1.1.0; added text predicates; version bump of dependencies
Signed-off-by: pm-osc <[email protected]>
1 parent 56dc2c1 commit d97d5aa

File tree

7 files changed

+212
-9
lines changed

7 files changed

+212
-9
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ of JanusGraph-Python:
6666
| JanusGraph-Python | JanusGraph |
6767
| ----------------- | ---------------------- |
6868
| 1.0.z | 1.0.z |
69+
| 1.1.z | 1.1.z |
6970

7071
While it should also be possible to use JanusGraph-Python with other versions of
7172
JanusGraph than mentioned here, compatibility is not tested and some

janusgraph_python/process/traversal.py

+91
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ def text_contains(*args):
4646
"""
4747
return _JanusGraphP("textContains", *args)
4848

49+
@staticmethod
50+
def text_not_contains(*args):
51+
"""
52+
Is true if no words inside the text string match the query string.
53+
54+
:param query: string, The query to search.
55+
:return The text predicate.
56+
"""
57+
return _JanusGraphP("textNotContains", *args)
58+
4959
@staticmethod
5060
def text_contains_prefix(*args):
5161
"""
@@ -56,6 +66,16 @@ def text_contains_prefix(*args):
5666
"""
5767
return _JanusGraphP("textContainsPrefix", *args)
5868

69+
@staticmethod
70+
def text_not_contains_prefix(*args):
71+
"""
72+
Is true if no words inside the text string begin with the query string.
73+
74+
:param query: string, The query to search.
75+
:return The text predicate.
76+
"""
77+
return _JanusGraphP("textNotContainsPrefix", *args)
78+
5979
@staticmethod
6080
def text_contains_regex(*args):
6181
"""
@@ -66,6 +86,16 @@ def text_contains_regex(*args):
6686
"""
6787
return _JanusGraphP("textContainsRegex", *args)
6888

89+
@staticmethod
90+
def text_not_contains_regex(*args):
91+
"""
92+
Is true if no words inside the text string match the given regular expression.
93+
94+
:param query: string, The query to search.
95+
:return The text predicate.
96+
"""
97+
return _JanusGraphP("textNotContainsRegex", *args)
98+
6999
@staticmethod
70100
def text_contains_fuzzy(*args):
71101
"""
@@ -77,6 +107,37 @@ def text_contains_fuzzy(*args):
77107
"""
78108
return _JanusGraphP("textContainsFuzzy", *args)
79109

110+
@staticmethod
111+
def text_not_contains_fuzzy(*args):
112+
"""
113+
Is true if no words inside the text string are similar to the query string
114+
(based on Levenshtein edit distance).
115+
116+
:param query: string, The query to search.
117+
:return The text predicate.
118+
"""
119+
return _JanusGraphP("textNotContainsFuzzy", *args)
120+
121+
@staticmethod
122+
def text_contains_phrase(*args):
123+
"""
124+
Is true if the text string does contain the sequence of words in the query string.
125+
126+
:param query: string, The query to search.
127+
:return The text predicate.
128+
"""
129+
return _JanusGraphP("textContainsPhrase", *args)
130+
131+
@staticmethod
132+
def text_not_contains_phrase(*args):
133+
"""
134+
Is true if the text string does not contain the sequence of words in the query string.
135+
136+
:param query: string, The query to search.
137+
:return The text predicate.
138+
"""
139+
return _JanusGraphP("textNotContainsPhrase", *args)
140+
80141
@staticmethod
81142
def text_prefix(*args):
82143
"""
@@ -87,6 +148,16 @@ def text_prefix(*args):
87148
"""
88149
return _JanusGraphP("textPrefix", *args)
89150

151+
@staticmethod
152+
def text_not_prefix(*args):
153+
"""
154+
Is true if the string value does not start with the given query string.
155+
156+
:param query: string, The query to search.
157+
:return The text predicate.
158+
"""
159+
return _JanusGraphP("textNotPrefix", *args)
160+
90161
@staticmethod
91162
def text_regex(*args):
92163
"""
@@ -97,6 +168,16 @@ def text_regex(*args):
97168
"""
98169
return _JanusGraphP("textRegex", *args)
99170

171+
@staticmethod
172+
def text_not_regex(*args):
173+
"""
174+
Is true if the string value does not match the given regular expression in its entirety.
175+
176+
:param query: string, The query to search.
177+
:return The text predicate.
178+
"""
179+
return _JanusGraphP("textNotRegex", *args)
180+
100181
@staticmethod
101182
def text_fuzzy(*args):
102183
"""
@@ -107,6 +188,16 @@ def text_fuzzy(*args):
107188
"""
108189
return _JanusGraphP("textFuzzy", *args)
109190

191+
@staticmethod
192+
def text_not_fuzzy(*args):
193+
"""
194+
Is true if the string value is not similar to the given query string (based on Levenshtein edit distance).
195+
196+
:param query: string, The query to search.
197+
:return The text predicate.
198+
"""
199+
return _JanusGraphP("textNotFuzzy", *args)
200+
110201
class RelationIdentifier(object):
111202
_TO_STRING_DELIMITER = '-'
112203

requirements.txt

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
aiohttp==3.10.10
2-
3-
# on Python 3.11 and 3.12 this is not installed automatically as dependency of aiohttp
4-
async-timeout==4.0.3
5-
6-
gremlinpython==3.7.2
1+
gremlinpython==3.7.3

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def read_requirements(path):
1818

1919
setup(
2020
name='janusgraphpython',
21-
version='1.0.0',
21+
version='1.1.0',
2222
description='JanusGraph-Python extends Apache TinkerPop™''s Gremlin-Python with support for JanusGraph-specific types.',
2323
long_description=(this_directory/'README.md').read_text(),
2424
long_description_content_type='text/markdown',

tests/integration/Text_test.py

+108-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ def test_text_contains_given_search_text(self, search_text, expected_count):
3030
count = self.g.E().has('reason', Text.text_contains(search_text)).count().next()
3131
assert count == expected_count
3232

33+
@mark.parametrize(
34+
'search_text,expected_count',
35+
[
36+
param('loves', 1),
37+
param('shouldNotBeFound', 3),
38+
]
39+
)
40+
def test_text_not_contains_given_search_text(self, search_text, expected_count):
41+
count = self.g.E().has('reason', Text.text_not_contains(search_text)).count().next()
42+
assert count == expected_count
43+
3344
@mark.parametrize(
3445
'search_text,expected_count',
3546
[
@@ -42,6 +53,18 @@ def test_text_contains_prefix_given_search_text(self, search_text, expected_coun
4253
count = self.g.E().has('reason', Text.text_contains_prefix(search_text)).count().next()
4354
assert count == expected_count
4455

56+
@mark.parametrize(
57+
'search_text,expected_count',
58+
[
59+
param('wave', 2),
60+
param('f', 1),
61+
param('shouldNotBeFound', 3),
62+
]
63+
)
64+
def test_text_contains_not_prefix_given_search_text(self, search_text, expected_count):
65+
count = self.g.E().has('reason', Text.text_not_contains_prefix(search_text)).count().next()
66+
assert count == expected_count
67+
4568
@mark.parametrize(
4669
'search_text,expected_count',
4770
[
@@ -54,6 +77,18 @@ def test_text_contains_regex_given_search_text(self, search_text, expected_count
5477
count = self.g.E().has('reason', Text.text_contains_regex(search_text)).count().next()
5578
assert count == expected_count
5679

80+
@mark.parametrize(
81+
'search_text,expected_count',
82+
[
83+
param('.*ave.*', 2),
84+
param('f.{3,4}', 1),
85+
param('shouldNotBeFound', 3),
86+
]
87+
)
88+
def test_text_not_contains_regex_given_search_text(self, search_text, expected_count):
89+
count = self.g.E().has('reason', Text.text_not_contains_regex(search_text)).count().next()
90+
assert count == expected_count
91+
5792
@mark.parametrize(
5893
'search_text,expected_count',
5994
[
@@ -65,6 +100,43 @@ def test_text_contains_fuzzy_given_search_text(self, search_text, expected_count
65100
count = self.g.E().has('reason', Text.text_contains_fuzzy(search_text)).count().next()
66101
assert count == expected_count
67102

103+
@mark.parametrize(
104+
'search_text,expected_count',
105+
[
106+
param('waxes', 2),
107+
param('shouldNotBeFound', 3),
108+
]
109+
)
110+
def test_text_not_contains_fuzzy_given_search_text(self, search_text, expected_count):
111+
count = self.g.E().has('reason', Text.text_not_contains_fuzzy(search_text)).count().next()
112+
assert count == expected_count
113+
114+
@mark.parametrize(
115+
'search_text,expected_count',
116+
[
117+
param('fresh breezes', 1),
118+
param('no fear', 1),
119+
param('fear of', 1),
120+
param('should not be found', 0),
121+
]
122+
)
123+
def test_text_contains_phrase_given_search_text(self, search_text, expected_count):
124+
count = self.g.E().has('reason', Text.text_contains_phrase(search_text)).count().next()
125+
assert count == expected_count
126+
127+
@mark.parametrize(
128+
'search_text,expected_count',
129+
[
130+
param('fresh breezes', 2),
131+
param('no fear', 2),
132+
param('fear of', 2),
133+
param('should not be found', 3),
134+
]
135+
)
136+
def test_text_not_contains_phrase_given_search_text(self, search_text, expected_count):
137+
count = self.g.E().has('reason', Text.text_not_contains_phrase(search_text)).count().next()
138+
assert count == expected_count
139+
68140
@mark.parametrize(
69141
'search_text,expected_count',
70142
[
@@ -77,6 +149,18 @@ def test_text_prefix_given_search_text(self, search_text, expected_count):
77149
count = self.g.V().has('name', Text.text_prefix(search_text)).count().next()
78150
assert count == expected_count
79151

152+
@mark.parametrize(
153+
'search_text,expected_count',
154+
[
155+
param('herc', 11),
156+
param('s', 9),
157+
param('shouldNotBeFound', 12),
158+
]
159+
)
160+
def test_text_not_prefix_given_search_text(self, search_text, expected_count):
161+
count = self.g.V().has('name', Text.text_not_prefix(search_text)).count().next()
162+
assert count == expected_count
163+
80164
@mark.parametrize(
81165
'search_text,expected_count',
82166
[
@@ -89,6 +173,18 @@ def test_text_regex_given_search_text(self, search_text, expected_count):
89173
count = self.g.V().has('name', Text.text_regex(search_text)).count().next()
90174
assert count == expected_count
91175

176+
@mark.parametrize(
177+
'search_text,expected_count',
178+
[
179+
param('.*rcule.*', 11),
180+
param('s.{2}', 10),
181+
param('shouldNotBeFound', 12),
182+
]
183+
)
184+
def test_text_not_regex_given_search_text(self, search_text, expected_count):
185+
count = self.g.V().has('name', Text.text_not_regex(search_text)).count().next()
186+
assert count == expected_count
187+
92188
@mark.parametrize(
93189
'search_text,expected_count',
94190
[
@@ -100,4 +196,15 @@ def test_text_regex_given_search_text(self, search_text, expected_count):
100196
def test_text_fuzzy_given_search_text(self, search_text, expected_count):
101197
count = self.g.V().has('name', Text.text_fuzzy(search_text)).count().next()
102198
assert count == expected_count
103-
199+
200+
@mark.parametrize(
201+
'search_text,expected_count',
202+
[
203+
param('herculex', 11),
204+
param('ska', 10),
205+
param('shouldNotBeFound', 12),
206+
]
207+
)
208+
def test_text_not_fuzzy_given_search_text(self, search_text, expected_count):
209+
count = self.g.V().has('name', Text.text_not_fuzzy(search_text)).count().next()
210+
assert count == expected_count

tests/integration/config.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[docker]
2-
image = janusgraph/janusgraph:1.0.0
2+
image = janusgraph/janusgraph:1.1.0

tests/unit/process/test_traversal.py

+9
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,21 @@ class TestText(object):
219219
'predicate,expected',
220220
[
221221
param(Text.text_contains('John'), 'textContains(John)', id='text_contains'),
222+
param(Text.text_not_contains('John'), 'textNotContains(John)', id='text_not_contains'),
222223
param(Text.text_contains_prefix('John'), 'textContainsPrefix(John)', id='text_contains_prefix'),
224+
param(Text.text_not_contains_prefix('John'), 'textNotContainsPrefix(John)', id='text_not_contains_prefix'),
223225
param(Text.text_contains_fuzzy('Juhn'), 'textContainsFuzzy(Juhn)', id='text_contains_fuzzy'),
226+
param(Text.text_not_contains_fuzzy('Juhn'), 'textNotContainsFuzzy(Juhn)', id='text_not_contains_fuzzy'),
224227
param(Text.text_contains_regex('.*hn.*'), 'textContainsRegex(.*hn.*)', id='text_contains_regex'),
228+
param(Text.text_not_contains_regex('.*hn.*'), 'textNotContainsRegex(.*hn.*)', id='text_not_contains_regex'),
229+
param(Text.text_contains_phrase('John Doe'), 'textContainsPhrase(John Doe)', id='text_contains_phrase'),
230+
param(Text.text_not_contains_phrase('John Doe'), 'textNotContainsPhrase(John Doe)', id='text_not_contains_phrase'),
225231
param(Text.text_fuzzy('Juhn'), 'textFuzzy(Juhn)', id='text_fuzzy'),
232+
param(Text.text_not_fuzzy('Juhn'), 'textNotFuzzy(Juhn)', id='text_not_fuzzy'),
226233
param(Text.text_prefix('John'), 'textPrefix(John)', id='text_prefix'),
234+
param(Text.text_not_prefix('John'), 'textNotPrefix(John)', id='text_not_prefix'),
227235
param(Text.text_regex('.*hn.*'), 'textRegex(.*hn.*)', id='text_regex'),
236+
param(Text.text_not_regex('.*hn.*'), 'textNotRegex(.*hn.*)', id='text_not_regex'),
228237
]
229238
)
230239
def test_Text(self, predicate, expected):

0 commit comments

Comments
 (0)