-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
anh.vu2
committed
Sep 12, 2021
1 parent
6b1acfe
commit cd18f57
Showing
9 changed files
with
20,867 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from elasticsearch import Elasticsearch | ||
from elasticsearch_dsl import Search | ||
|
||
|
||
class Dictionary: | ||
def __init__(self, es_index='dictionary'): | ||
self.es_index = es_index | ||
self.es = Elasticsearch() | ||
s = Search(using=self.es, index=es_index) | ||
ids = [h.meta.id for h in s.scan()] | ||
words = sorted(ids) | ||
self.words = words | ||
|
||
def get_word(self, word): | ||
if word not in self.words: | ||
return {} | ||
print(word) | ||
body = self.es.get(index=self.es_index, id=word) | ||
data = body["_source"] | ||
return data | ||
|
||
def save(self, word, data): | ||
self.es.index(index=self.es_index, id=word, body=data) | ||
|
||
|
||
if __name__ == '__main__': | ||
dictionary = Dictionary(es_index='dictionary') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from elasticsearch import Elasticsearch | ||
from apps.utils import DICTIONARY_FILE | ||
import yaml | ||
|
||
if __name__ == '__main__': | ||
with open(DICTIONARY_FILE) as f: | ||
content = f.read() | ||
|
||
es = Elasticsearch() | ||
|
||
words = yaml.safe_load(content) | ||
i = 0 | ||
for word_key, value in words.items(): | ||
i += 1 | ||
data = { | ||
"headword": word_key, | ||
"senses": value | ||
} | ||
es.index(index='dictionary', body=data, id=word_key) | ||
if i % 1000 == 0 and i > 0: | ||
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Elasticsearch | ||
|
||
We use elasticsearch as our main database, elasticsearch will sync with dictionary.yaml dictionary file | ||
|
||
Installation | ||
|
||
``` | ||
docker volume create esdata1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: '2.2' | ||
services: | ||
elasticsearch: | ||
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.18 | ||
container_name: elasticsearch | ||
environment: | ||
- cluster.name=docker-cluster | ||
- bootstrap.memory_lock=true | ||
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" | ||
ulimits: | ||
memlock: | ||
soft: -1 | ||
hard: -1 | ||
volumes: | ||
- esdata1:/usr/share/elasticsearch/data | ||
ports: | ||
- 9200:9200 | ||
networks: | ||
- esnet | ||
volumes: | ||
esdata1: | ||
driver: local | ||
|
||
networks: | ||
esnet: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from os.path import abspath, dirname, join | ||
|
||
PROJECT_FOLDER = dirname(dirname(abspath(__file__))) | ||
DICTIONARY_FILE = join(PROJECT_FOLDER, "datasets", "UD_Vietnamese-COL", "dictionary", "dictionary.yaml") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.