File size: 1,092 Bytes
974e1e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import os
import warnings
import time

import spacy

from project_settings import project_path


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--text",
        type=str,
        default="Mr. Honey Tian. How are you."
    )
    # https://huggingface.co/stanfordnlp
    parser.add_argument(
        "--language",
        type=str,
        default="english"
    )
    args = parser.parse_args()
    return args


# https://spacy.io/models
language_to_models = {
    "english": "en_core_web_sm",
    # "english": "en_core_web_md",
    # "english": "en_core_web_lg",
    # "english": "en_core_web_trf",

}


def main():
    args = get_args()

    model_name = language_to_models[args.language]

    spacy_nlp = spacy.load(model_name)

    begin_time = time.time()
    doc = spacy_nlp(args.text)
    sentences = [sentence.text for sentence in doc.sents]

    cost = time.time() - begin_time
    print(f"time cost: {cost}")

    print(sentences)
    return


if __name__ == "__main__":
    main()