-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathQuerySplitter.py
More file actions
28 lines (24 loc) · 827 Bytes
/
Copy pathQuerySplitter.py
File metadata and controls
28 lines (24 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
# encoding: utf-8
class QuerySplitter(object):
def __init__(self, query):
self.tags = str()
self.title = str()
self.zettel_id = str()
self._split(query)
def _isZettelId(self, text):
zettel_id = str(text)
return True if len(zettel_id) == 12 and zettel_id.isdigit() else False
def _split(self, query):
parts = query.split(' ')
title_list = list()
tag_list = list()
for part in parts:
if str(part).startswith('#'):
tag_list.append(part)
elif self._isZettelId(part) and self.zettel_id == str():
self.zettel_id = part
else:
title_list.append(part)
self.title = ' '.join(title_list)
self.tags = ' '.join(tag_list)