• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PyThaiNLP / pythainlp / 11625814262

01 Nov 2024 07:14AM UTC coverage: 20.782% (+20.8%) from 0.0%
11625814262

Pull #952

github

web-flow
Merge c8385dcae into 515fe7ced
Pull Request #952: Specify a limited test suite

45 of 80 new or added lines in 48 files covered. (56.25%)

1537 of 7396 relevant lines covered (20.78%)

0.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.27
/pythainlp/coref/core.py
1
# -*- coding: utf-8 -*-
2
# SPDX-FileCopyrightText: 2016-2024 PyThaiNLP Project
3
# SPDX-License-Identifier: Apache-2.0
4
from typing import List
1✔
5

6
_MODEL = None
1✔
7

8

9
def coreference_resolution(
1✔
10
    texts: List[str], model_name: str = "han-coref-v1.0", device: str = "cpu"
11
):
12
    """
13
    Coreference Resolution
14

15
    :param List[str] texts: list of texts to apply coreference resolution to
16
    :param str model_name: coreference resolution model
17
    :param str device: device for running coreference resolution model on\
18
        ("cpu", "cuda", and others)
19
    :return: List of texts with coreference resolution
20
    :rtype: List[dict]
21

22
    :Options for model_name:
23
        * *han-coref-v1.0* - (default) Han-Coref: Thai coreference resolution\
24
            by PyThaiNLP v1.0
25

26
    :Example:
27
    ::
28

29
        from pythainlp.coref import coreference_resolution
30

31
        print(
32
            coreference_resolution(
33
                ["Bill Gates ได้รับวัคซีน COVID-19 เข็มแรกแล้ว ระบุ ผมรู้สึกสบายมาก"]
34
            )
35
        )
36
        # output:
37
        # [
38
        # {'text': 'Bill Gates ได้รับวัคซีน COVID-19 เข็มแรกแล้ว ระบุ ผมรู้สึกสบายมาก',
39
        # 'clusters_string': [['Bill Gates', 'ผม']],
40
        # 'clusters': [[(0, 10), (50, 52)]]}
41
        # ]
42
    """
43
    global _MODEL
44
    if isinstance(texts, str):
×
45
        texts = [texts]
×
46

NEW
47
    if _MODEL is None and model_name == "han-coref-v1.0":
×
48
        from pythainlp.coref.han_coref import HanCoref
×
49

NEW
50
        _MODEL = HanCoref(device=device)
×
51

NEW
52
    if _MODEL:
×
NEW
53
        return _MODEL.predict(texts)
×
54

55
    return [
×
56
        {"text": text, "clusters_string": [], "clusters": []} for text in texts
57
    ]
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc