### Initialize ArticutTG Class
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
Demonstrates how to initialize the ArticutTG class for processing Taiwanese Hokkien text. It shows initialization with free public quotas, paid accounts, and optionally with English Articut accounts for English name recognition.
```python
from ArticutAPI_Taigi import ArticutTG
# 使用免費公用額度
articutTG = ArticutTG(username="", apikey="")
# 使用付費帳號
username = "your_email@example.com"
apikey = "your_api_key_here"
articutTG = ArticutTG(username=username, apikey=apikey)
# 若需要英文人名辨識功能,可同時提供英文版 Articut 的帳號
articutTG = ArticutTG(
username="chinese_account@example.com",
apikey="chinese_api_key",
usernameENG="english_account@example.com",
apikeyENG="english_api_key"
)
```
--------------------------------
### Perform Basic NLP Tasks with ArticutAPI_Taigi
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
Demonstrates how to initialize the ArticutTG client and perform basic segmentation, POS tagging, and NER on a Taiwanese input string.
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
username = "" #這裡填入您在 https://api.droidtown.co 使用的帳號 email。
apikey = "" #這裡填入您在 https://api.droidtown.co 登入後取得的 api Key。
articutTG = ArticutTG(username, apikey)
inputSTR = "歡迎逐家做伙來做台灣語言"
resultDICT = articutTG.parse(inputSTR, level="lv2") #lv2 為預設值
pprint(resultDICT)
```
--------------------------------
### Basic Operations: Word Segmentation (WS) / Part-of-Speech Tagging (POS) / Named Entity Recognition (NER)
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
This section demonstrates how to perform basic NLP tasks like word segmentation, POS tagging, and NER on Taiwanese Hokkien text using the ArticutTG class. It shows how to initialize the class with optional username and API key, and how to call the parse method with different levels.
```APIDOC
## Basic Operations: Word Segmentation (WS) / Part-of-Speech Tagging (POS) / Named Entity Recognition (NER)
### Description
This endpoint performs word segmentation, part-of-speech tagging, and named entity recognition on Taiwanese Hokkien text.
### Method
POST
### Endpoint
/api/segmentation
### Parameters
#### Query Parameters
- **username** (string) - Optional - Your username for authentication. Defaults to public quota.
- **apikey** (string) - Optional - Your API key for authentication. Defaults to public quota.
- **level** (string) - Optional - The level of analysis. Defaults to 'lv2'.
### Request Body
```json
{
"inputSTR": "歡迎逐家做伙來做台灣語言"
}
```
### Request Example
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
username = "" # Enter your Articut API username here. Defaults to public quota if empty.
apikey = "" # Enter your Articut API key here. Defaults to public quota if empty.
articutTG = ArticutTG(username, apikey)
inputSTR = "歡迎逐家做伙來做台灣語言"
resultDICT = articutTG.parse(inputSTR, level="lv2") # lv2 is the default level
pprint(resultDICT)
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the request was successful.
- **message** (string) - A message describing the result.
- **result_obj** (array) - Detailed results of the NLP analysis.
- **result_pos** (array) - Part-of-speech tagged text.
- **result_segmentation** (string) - The segmented text.
- **exec_time** (float) - Execution time in seconds.
- **word_count_balance** (integer) - Remaining word count balance.
#### Response Example
```json
{
"exec_time": 0.17456531524658203,
"level": "lv2",
"msg": "Success!",
"result_obj": [
{
"pos": "ACTION_verb",
"text": "歡迎"
},
{
"pos": "ENTITY_pronoun",
"text": "逐家"
},
{
"pos": "MODIFIER",
"text": "做伙"
},
{
"pos": "ACTION_verb",
"text": "來"
},
{
"pos": "ACTION_verb",
"text": "做"
},
{
"pos": "LOCATION",
"text": "台灣"
},
{
"pos": "ENTITY_noun",
"text": "語言"
}
],
"result_pos": [
"歡迎逐家做伙來做台灣語言"
],
"result_segmentation": "歡迎/逐家/做伙/來/做/台灣/語言",
"status": true,
"version": "v261",
"word_count_balance": 1965
}
```
```
--------------------------------
### Define Custom Dictionaries for ArticutAPI_Taigi
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
Shows the JSON structure required for custom dictionaries and how to pass the file path to the parse method.
```json
{
"ACTION_verb": [],
"ENTITY_noun": [],
"LOCATION": [],
"MODIFIER": []
}
```
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
articutTG = ArticutTG("", "")
inputSTR = "歡迎逐家做伙來做台灣語言"
resultDICT = articutTG.parse(inputSTR, level="lv2", userDefinedDictFILE="my_dictionary.json")
pprint(resultDICT)
```
--------------------------------
### Using Custom Dictionaries
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
Explains how to use the userDefinedDictFILE parameter to load a custom dictionary JSON file. This allows for extending or overriding the default vocabulary. The dictionary format must adhere to the specified part-of-speech classification structure.
```python
from ArticutAPI_Taigi import ArticutTG
import json
articutTG = ArticutTG(username="", apikey="")
```
--------------------------------
### Basic Word Segmentation and POS Tagging (lv2)
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
Shows how to use the parse() method with level='lv2' for basic word segmentation and Part-of-Speech tagging of Taiwanese Hokkien text. It returns a dictionary containing segmentation, POS tags, and Named Entity Recognition results. It also demonstrates handling mixed input of Taiwanese Hokkien and Tâi-lô.
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
articutTG = ArticutTG(username="", apikey="")
inputSTR = "歡迎逐家做伙來做台灣語言"
# 基本斷詞與詞性標記
resultDICT = articutTG.parse(inputSTR, level="lv2")
pprint(resultDICT)
# 處理台羅拼音混打
mixedSTR = "你ē-sái請ta̍k-ke提供字句hō͘你做這個試驗"
resultDICT = articutTG.parse(mixedSTR, level="lv2")
pprint(resultDICT['result_segmentation'])
```
--------------------------------
### Using Custom Dictionaries
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
This section explains how to use custom dictionaries to enhance the NLP analysis. It provides the JSON structure for a custom dictionary and demonstrates how to specify a dictionary file in the parse method.
```APIDOC
## Using Custom Dictionaries
### Description
ArticutAPI_Taigi supports custom dictionary configurations to improve NLP accuracy. Dictionaries should be saved as JSON files.
### Method
POST
### Endpoint
/api/segmentation
### Parameters
#### Query Parameters
- **username** (string) - Optional - Your username for authentication. Defaults to public quota.
- **apikey** (string) - Optional - Your API key for authentication. Defaults to public quota.
- **level** (string) - Optional - The level of analysis. Defaults to 'lv2'.
- **userDefinedDictFILE** (string) - Optional - Path to the custom dictionary JSON file.
### Request Body
```json
{
"inputSTR": "歡迎逐家做伙來做台灣語言"
}
```
### Custom Dictionary Structure
```json
{
"ACTION_verb": [],
"ACTION_lightVerb": [],
"ACTION_quantifiedVerb": [],
"ACTION_eventQuantifier": [],
"ASPECT": [],
"AUX": [],
"CLAUSE_particle": [],
"CLAUSE_Q": [],
"ENTITY_classifier": [],
"ENTITY_DetPhrase": [],
"ENTITY_measurement": [],
"ENTITY_noun": [],
"ENTITY_num": [],
"ENTITY_person": [],
"ENTITY_possessive": [],
"ENTITY_pronoun": [],
"FUNC_conjunction": [],
"FUNC_degreeHead": [],
"FUNC_inner": [],
"FUNC_inter": [],
"FUNC_negation": [],
"IDIOM": [],
"LOCATION": [],
"MODAL": [],
"MODIFIER": [],
"MODIFIER_color": [],
"QUANTIFIER": [],
"RANGE_locality": [],
"RANGE_period": [],
"TIME_justtime": [],
"TIME_season": []
}
```
### Request Example
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
username = "" # Enter your Articut API username here. Defaults to public quota if empty.
apikey = "" # Enter your Articut API key here. Defaults to public quota if empty.
articutTG = ArticutTG(username, apikey)
inputSTR = "歡迎逐家做伙來做台灣語言"
resultDICT = articutTG.parse(inputSTR, level="lv2", userDefinedDictFILE="my_dictionary.json")
pprint(resultDICT)
```
```
--------------------------------
### 獲取詞性標記列表與解析結果
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
列出 ArticutAPI_Taigi 支援的詞性標記類別,並示範如何遍歷解析結果中的詞彙與對應標記。
```python
from ArticutAPI_Taigi import ArticutTG
POS_CATEGORIES = {
"ACTION_verb": "普通動詞",
"ENTITY_noun": "普通名詞",
"FUNC_negation": "否定詞"
}
articutTG = ArticutTG(username="", apikey="")
resultDICT = articutTG.parse("伊誠𠢕激五仁,激甲逐家笑咍咍", level="lv2")
for sentence in resultDICT['result_obj']:
for word_info in sentence:
print(f"詞彙: {word_info['text']}, 詞性: {word_info['pos']}")
```
--------------------------------
### 批次處理台語文本
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
示範如何透過迴圈批次處理多個台語句子,並監控 API 的剩餘額度以確保服務穩定。
```python
from ArticutAPI_Taigi import ArticutTG
articutTG = ArticutTG(username="", apikey="")
inputLIST = ["張總的頂擺出張", "物件揀好去揣店員結數"]
for inputSTR in inputLIST:
resultDICT = articutTG.parse(inputSTR, level="lv2")
print(f"輸入: {inputSTR}")
print(f"斷詞: {resultDICT['result_segmentation']}")
print(f"剩餘額度: {resultDICT['word_count_balance']}")
```
--------------------------------
### Tâi-lô Conversion with parse() (lv3)
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
Demonstrates using the parse() method with level='lv3' to perform word segmentation and convert Taiwanese Hokkien text to Tâi-lô (Taiwanese Romanization System) pronunciation. The 'utterance' field in the returned dictionary contains the Tâi-lô results, with multi-pronunciation words indicated in parentheses. It also shows how to extract named entities.
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
articutTG = ArticutTG(username="", apikey="")
inputSTR = "歡迎逐家做伙來做台灣語言"
# 轉換為台羅拼音
resultDICT = articutTG.parse(inputSTR, level="lv3")
pprint(resultDICT)
# 取得拼音結果
print("台羅拼音:", resultDICT['utterance'])
# 取得命名實體
print("人物:", resultDICT['person'])
print("地點:", resultDICT['site'])
print("實體:", resultDICT['entity'])
```
--------------------------------
### Perform Advanced Transliteration
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
Demonstrates how to use the API to convert between different Taiwanese orthographies by setting the processing level to lv3.
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
articutTG = ArticutTG("", "")
inputSTR = "歡迎逐家做伙來做台灣語言"
resultDICT = articutTG.parse(inputSTR, level="lv3")
pprint(resultDICT)
```
--------------------------------
### Extracting POS Tags from Articut Result
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
Demonstrates how to parse the result_obj from ArticutTG to extract specific parts of speech such as verbs, nouns, locations, and persons. It also shows how to perform frequency counting of POS tags using the collections module.
```python
from ArticutAPI_Taigi import ArticutTG
from collections import Counter
articutTG = ArticutTG(username="", apikey="")
inputSTR = "阿明昨暗去台北看電影,真歡喜"
resultDICT = articutTG.parse(inputSTR, level="lv2")
verbs = [word['text'] for sentence in resultDICT['result_obj'] for word in sentence if word['pos'].startswith('ACTION')]
print("動詞列表:", verbs)
nouns = [word['text'] for sentence in resultDICT['result_obj'] for word in sentence if word['pos'].startswith('ENTITY_noun')]
print("名詞列表:", nouns)
pos_counter = Counter(word['pos'] for sentence in resultDICT['result_obj'] for word in sentence)
print("詞性統計:", dict(pos_counter))
```
--------------------------------
### Accessing Named Entity Recognition (NER) Results
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
Explains how to use level='lv3' to retrieve structured named entity information including persons, locations, time, and entities, alongside Romanization and API metadata.
```python
from ArticutAPI_Taigi import ArticutTG
articutTG = ArticutTG(username="", apikey="")
inputSTR = "阿明聽了,煞想著一个問題:若準風颱嘛算是一種自然的現象,為啥物咱猶原愛驚惶伊"
resultDICT = articutTG.parse(inputSTR, level="lv3")
print("人物:", resultDICT['person'])
print("地點:", resultDICT['site'])
print("台羅拼音:", resultDICT['utterance'])
print("剩餘額度:", resultDICT['word_count_balance'])
```
--------------------------------
### 建立並使用自訂詞典進行斷詞
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
展示如何定義自訂詞典 JSON 檔案,並將其傳入 ArticutAPI_Taigi 進行斷詞與詞性標記分析。
```python
import json
from ArticutAPI_Taigi import ArticutTG
custom_dict = {
"ACTION_verb": ["講話", "走跳"],
"FUNC_negation": ["不", "沒", "嘸"],
"ENTITY_noun": ["電腦", "手機仔"]
}
with open("my_dictionary.json", "w", encoding="utf-8") as f:
json.dump(custom_dict, f, ensure_ascii=False, indent=4)
articutTG = ArticutTG(username="", apikey="")
inputSTR = "阿明佮阿花去台北𨑨迌"
resultDICT = articutTG.parse(inputSTR, level="lv2", userDefinedDictFILE="my_dictionary.json")
print("斷詞結果:", resultDICT['result_segmentation'])
print("詞性標記:", resultDICT['result_pos'])
```
--------------------------------
### POST /parse - Text Segmentation and POS Tagging
Source: https://context7.com/droidtown/articutapi_taigi/llms.txt
Performs morphological analysis on a given Taiwanese Hokkien string, returning segmented text and POS tags. Supports custom user-defined dictionaries.
```APIDOC
## POST /parse
### Description
Parses a Taiwanese Hokkien string to perform segmentation and part-of-speech (POS) tagging. Users can provide a custom JSON dictionary file to improve accuracy for specific domains.
### Method
POST
### Endpoint
/parse
### Parameters
#### Query Parameters
- **level** (string) - Required - The granularity level of the analysis (e.g., "lv2").
- **userDefinedDictFILE** (string) - Optional - Path to a JSON file containing custom vocabulary mappings.
#### Request Body
- **inputSTR** (string) - Required - The Taiwanese Hokkien text to be analyzed.
### Request Example
{
"inputSTR": "阿明佮阿花去台北𨑨迌",
"level": "lv2",
"userDefinedDictFILE": "my_dictionary.json"
}
### Response
#### Success Response (200)
- **result_segmentation** (string) - The segmented output string.
- **result_pos** (string) - The POS tags associated with the segments.
- **word_count_balance** (integer) - Remaining API usage quota.
#### Response Example
{
"result_segmentation": "阿明/佮/阿花/去/台北/𨑨迌",
"result_pos": "ENTITY_person/FUNC_conjunction/ENTITY_person/ACTION_verb/LOCATION/ACTION_verb",
"word_count_balance": 9850
}
```
--------------------------------
### Articut API Taigi Response Structure
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
This snippet shows the typical JSON response structure from the Articut API for Taigi language processing, including extracted entities, execution time, and processing status.
```APIDOC
## Articut API Taigi Response
### Description
This section describes the structure of the response returned by the Articut API when processing Taigi language.
### Method
POST
### Endpoint
/droidtown/articutapi_taigi
### Response
#### Success Response (200)
- **entity** (list of lists of tuples) - Detected entities in the text, each tuple contains (start_index, end_index, entity_type).
- **exec_time** (float) - The time taken for the API to process the request in seconds.
- **level** (string) - The processing level of the analysis (e.g., 'lv3').
- **msg** (string) - A message indicating the status of the operation (e.g., 'Success!').
- **person** (list of lists of tuples) - Detected person names.
- **site** (list of lists of tuples) - Detected location names.
- **status** (boolean) - True if the operation was successful, False otherwise.
- **time** (list of lists) - Detected time expressions.
- **utterance** (string) - The original input text after normalization.
- **version** (string) - The version of the Articut API used.
- **word_count_balance** (integer) - Remaining word count balance for the API key.
#### Response Example
```json
{
"entity": [[(179, 181, "語言")]],
"exec_time": 0.1532421112060547,
"level": "lv3",
"msg": "Success!",
"person": [[(45, 47, "逐家")]],
"site": [[(153, 155, "台灣")]],
"status": true,
"time": [[]],
"utterance": "huan-gîng╱ta̍k-ke╱(tsò-hué/tsuè-hé)╱lâi╱(tsò/tsuè)╱tâi-(uan/uân)╱(gí-giân/gú-giân)",
"version": "v261",
"word_count_balance": 1965
}
```
```
--------------------------------
### ArticutAPI Taigi Response Format
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
This snippet illustrates the structure of the JSON response returned by the ArticutAPI. It includes extracted entities, execution time, status flags, and the tokenized utterance.
```python
{
"entity": [[(179, 181, "語言")]],
"exec_time": 0.1532421112060547,
"level": "lv3",
"msg": "Success!",
"person": [[(45, 47, "逐家")]],
"site": [[(153, 155, "台灣")]],
"status": true,
"time": [[]],
"utterance": "huan-gîng╱ta̍k-ke╱(tsò-hué/tsuè-hé)╱lâi╱(tsò/tsuè)╱tâi-(uan/uân)╱(gí-giân/gú-giân)",
"version": "v261",
"word_count_balance": 1965
}
```
--------------------------------
### Advanced Operations: Taiwanese Hokkien to Taiwan Romanized Phonetic Transcription
Source: https://github.com/droidtown/articutapi_taigi/blob/main/README.md
This section covers the advanced functionality of converting Taiwanese Hokkien text into Taiwan Romanized phonetic transcription. It shows how to use the parse method with `level='lv3'` to achieve this conversion.
```APIDOC
## Advanced Operations: Taiwanese Hokkien to Taiwan Romanized Phonetic Transcription
### Description
This endpoint converts Taiwanese Hokkien text, including characters and romanized phonetics, into a standardized Taiwan Romanized phonetic transcription.
### Method
POST
### Endpoint
/api/transcription
### Parameters
#### Query Parameters
- **username** (string) - Optional - Your username for authentication. Defaults to public quota.
- **apikey** (string) - Optional - Your API key for authentication. Defaults to public quota.
- **level** (string) - Required - Set to 'lv3' for phonetic transcription.
### Request Body
```json
{
"inputSTR": "歡迎逐家做伙來做台灣語言"
}
```
### Request Example
```python
from ArticutAPI_Taigi import ArticutTG
from pprint import pprint
username = "" # Enter your Articut API username here. Defaults to public quota if empty.
apikey = "" # Enter your Articut API key here. Defaults to public quota if empty.
articutTG = ArticutTG(username, apikey)
inputSTR = "歡迎逐家做伙來做台灣語言"
resultDICT = articutTG.parse(inputSTR, level="lv3") # Change the default level from lv2 to lv3
pprint(resultDICT)
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the request was successful.
- **message** (string) - A message describing the result.
- **result_obj** (array) - Detailed results of the phonetic transcription.
- **exec_time** (float) - Execution time in seconds.
- **word_count_balance** (integer) - Remaining word count balance.
#### Response Example
(Response structure for lv3 will be similar to lv2 but with phonetic transcription details)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.