Skip to content

Commit b1c71c7

Browse files
Merge pull request #86 from pm-osc/jg-1.1
support for JanusGraph 1.1.0; added text predicates; version bump of dependencies
2 parents 56dc2c1 + 5cedbd0 commit b1c71c7

File tree

10 files changed

+336
-54
lines changed

10 files changed

+336
-54
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.0.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

+117-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ 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+
@mark.minimum_janusgraph_version("1.1.0")
41+
def test_text_not_contains_given_search_text(self, search_text, expected_count):
42+
count = self.g.E().has('reason', Text.text_not_contains(search_text)).count().next()
43+
assert count == expected_count
44+
3345
@mark.parametrize(
3446
'search_text,expected_count',
3547
[
@@ -42,6 +54,19 @@ def test_text_contains_prefix_given_search_text(self, search_text, expected_coun
4254
count = self.g.E().has('reason', Text.text_contains_prefix(search_text)).count().next()
4355
assert count == expected_count
4456

57+
@mark.parametrize(
58+
'search_text,expected_count',
59+
[
60+
param('wave', 2),
61+
param('f', 1),
62+
param('shouldNotBeFound', 3),
63+
]
64+
)
65+
@mark.minimum_janusgraph_version("1.1.0")
66+
def test_text_contains_not_prefix_given_search_text(self, search_text, expected_count):
67+
count = self.g.E().has('reason', Text.text_not_contains_prefix(search_text)).count().next()
68+
assert count == expected_count
69+
4570
@mark.parametrize(
4671
'search_text,expected_count',
4772
[
@@ -54,6 +79,19 @@ def test_text_contains_regex_given_search_text(self, search_text, expected_count
5479
count = self.g.E().has('reason', Text.text_contains_regex(search_text)).count().next()
5580
assert count == expected_count
5681

82+
@mark.parametrize(
83+
'search_text,expected_count',
84+
[
85+
param('.*ave.*', 2),
86+
param('f.{3,4}', 1),
87+
param('shouldNotBeFound', 3),
88+
]
89+
)
90+
@mark.minimum_janusgraph_version("1.1.0")
91+
def test_text_not_contains_regex_given_search_text(self, search_text, expected_count):
92+
count = self.g.E().has('reason', Text.text_not_contains_regex(search_text)).count().next()
93+
assert count == expected_count
94+
5795
@mark.parametrize(
5896
'search_text,expected_count',
5997
[
@@ -65,6 +103,46 @@ def test_text_contains_fuzzy_given_search_text(self, search_text, expected_count
65103
count = self.g.E().has('reason', Text.text_contains_fuzzy(search_text)).count().next()
66104
assert count == expected_count
67105

106+
@mark.parametrize(
107+
'search_text,expected_count',
108+
[
109+
param('waxes', 2),
110+
param('shouldNotBeFound', 3),
111+
]
112+
)
113+
@mark.minimum_janusgraph_version("1.1.0")
114+
def test_text_not_contains_fuzzy_given_search_text(self, search_text, expected_count):
115+
count = self.g.E().has('reason', Text.text_not_contains_fuzzy(search_text)).count().next()
116+
assert count == expected_count
117+
118+
@mark.parametrize(
119+
'search_text,expected_count',
120+
[
121+
param('fresh breezes', 1),
122+
param('no fear', 1),
123+
param('fear of', 1),
124+
param('should not be found', 0),
125+
]
126+
)
127+
@mark.minimum_janusgraph_version("1.1.0")
128+
def test_text_contains_phrase_given_search_text(self, search_text, expected_count):
129+
count = self.g.E().has('reason', Text.text_contains_phrase(search_text)).count().next()
130+
assert count == expected_count
131+
132+
@mark.parametrize(
133+
'search_text,expected_count',
134+
[
135+
param('fresh breezes', 2),
136+
param('no fear', 2),
137+
param('fear of', 2),
138+
param('should not be found', 3),
139+
]
140+
)
141+
@mark.minimum_janusgraph_version("1.1.0")
142+
def test_text_not_contains_phrase_given_search_text(self, search_text, expected_count):
143+
count = self.g.E().has('reason', Text.text_not_contains_phrase(search_text)).count().next()
144+
assert count == expected_count
145+
68146
@mark.parametrize(
69147
'search_text,expected_count',
70148
[
@@ -77,6 +155,19 @@ def test_text_prefix_given_search_text(self, search_text, expected_count):
77155
count = self.g.V().has('name', Text.text_prefix(search_text)).count().next()
78156
assert count == expected_count
79157

158+
@mark.parametrize(
159+
'search_text,expected_count',
160+
[
161+
param('herc', 11),
162+
param('s', 9),
163+
param('shouldNotBeFound', 12),
164+
]
165+
)
166+
@mark.minimum_janusgraph_version("1.1.0")
167+
def test_text_not_prefix_given_search_text(self, search_text, expected_count):
168+
count = self.g.V().has('name', Text.text_not_prefix(search_text)).count().next()
169+
assert count == expected_count
170+
80171
@mark.parametrize(
81172
'search_text,expected_count',
82173
[
@@ -89,6 +180,19 @@ def test_text_regex_given_search_text(self, search_text, expected_count):
89180
count = self.g.V().has('name', Text.text_regex(search_text)).count().next()
90181
assert count == expected_count
91182

183+
@mark.parametrize(
184+
'search_text,expected_count',
185+
[
186+
param('.*rcule.*', 11),
187+
param('s.{2}', 10),
188+
param('shouldNotBeFound', 12),
189+
]
190+
)
191+
@mark.minimum_janusgraph_version("1.1.0")
192+
def test_text_not_regex_given_search_text(self, search_text, expected_count):
193+
count = self.g.V().has('name', Text.text_not_regex(search_text)).count().next()
194+
assert count == expected_count
195+
92196
@mark.parametrize(
93197
'search_text,expected_count',
94198
[
@@ -100,4 +204,16 @@ def test_text_regex_given_search_text(self, search_text, expected_count):
100204
def test_text_fuzzy_given_search_text(self, search_text, expected_count):
101205
count = self.g.V().has('name', Text.text_fuzzy(search_text)).count().next()
102206
assert count == expected_count
103-
207+
208+
@mark.parametrize(
209+
'search_text,expected_count',
210+
[
211+
param('herculex', 11),
212+
param('ska', 10),
213+
param('shouldNotBeFound', 12),
214+
]
215+
)
216+
@mark.minimum_janusgraph_version("1.1.0")
217+
def test_text_not_fuzzy_given_search_text(self, search_text, expected_count):
218+
count = self.g.V().has('name', Text.text_not_fuzzy(search_text)).count().next()
219+
assert count == expected_count

tests/integration/config.ini

-2
This file was deleted.

tests/integration/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dockerRepository": "janusgraph/janusgraph",
3+
"dockerTags": ["1.0.1", "1.1.0"]
4+
}

0 commit comments

Comments
 (0)