Skip to content

Commit

Permalink
新增使用範例
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterWolf-tw committed Aug 21, 2019
1 parent 5ebd081 commit c47d4b4
Showing 1 changed file with 137 additions and 2 deletions.
139 changes: 137 additions & 2 deletions Docs/Articut-GraphQL/ReadMe_EN.md
Expand Up @@ -20,7 +20,7 @@ Articut-GraphQL can recognize [Person]、[Pronoun]、[Location]、[Route names

![ner_of_doc](../../Screenshots/ner_of_doc.png)

## Start Using Articut-GraphQL
## Using Articut-GraphQL
### System requirement

Python 3.6.1+
Expand All @@ -38,7 +38,142 @@ Currently, we only support "Traditional Chinese", so it has to be "TW" now.

**`model:"TW"`**

### Begin to operate GraphQL:
### doc Manual
```
text => Content of the text
tokens { => Attributes of the tokens
text => Text of the token
pos_ => SpaCy POS Tag
tag_ => Articut POS Tag
isStop
isEntity
isVerb
isTime
isClause
isKnowledge
}
ents {
persons { => Persons and Pronouns
text
pos_
tag_
}
nouns { => Nouns and Named Entities
text
pos_
tag_
}
numbers { => Numbers and Quantity Expressions
text
pos_
tag_
}
sites { => Location, Road names of Taiwan and Address of Taiwan
text
pos_
tag_
}
}
```

### Begin Using GraphQL

### Using GraphiQL

GraphiQL requuires modules listed below. You may install them easily with pip:

```
$ pip install graphene
$ pip install starlette
$ pip install jinja2
$ pip install uvicorn
```

Execute ArticutGraphQL.py with the filepath lead to the result of your text document processed with Articut. Then, open your Internet browser and use URL: `http://0.0.0.0:8000/`

```
$ python ArticutGraphQL.py articutResult.json
```

### Example 01
![GraphiQL Example 01](../../Screenshots/GraphiQL_Example01.png)

### Example 02
![GraphiQL Example 02](../../Screenshots/GraphiQL_Example02.png)

### Using Articut-GraphQL
`graphene` module is required, you may simply install graphene module with pip:

```
$ pip install graphene
```
### Example 01
```
inputSTR = "地址:宜蘭縣宜蘭市縣政北七路六段55巷1號2樓"
result = articut.parse(inputSTR)
with open("articutResult.json", "w", encoding="utf-8") as resultFile:
json.dump(result, resultFile, ensure_ascii=False)
graphQLResult = articut.graphQL.query(
filePath="articutResult.json",
query="""
{
meta {
lang
description
}
doc {
text
tokens {
text
pos_
tag_
isStop
isEntity
isVerb
isTime
isClause
isKnowledge
}
}
}""")
pprint(graphQLResult)
```

### Result:
![Articut-GraphQL Example 01](../../Screenshots/Articut-GraphQL_Example01.png)

### Example 02
```
inputSTR = inputSTR = "劉克襄在本次活動當中,分享了台北中山北路一日遊路線。他表示當初自己領著柯文哲一同探索了雙連市場與中山捷運站的小吃與商圈,還有商圈內的文創商店與日系雜物店鋪,都令柯文哲留下深刻的印象。劉克襄也認為,雙連市場內的魯肉飯、圓仔湯與切仔麵,還有九條通的日式店家、居酒屋等特色,也能讓人感受到台北舊城區不一樣的魅力。"
result = articut.parse(inputSTR)
with open("articutResult.json", "w", encoding="utf-8") as resultFile:
json.dump(result, resultFile, ensure_ascii=False)
graphQLResult = articut.graphQL.query(
filePath="articutResult.json",
query="""
{
meta {
lang
description
}
doc {
text
ents {
persons {
text
pos_
tag_
}
}
}
}""")
pprint(graphQLResult)
```

### Result:
![Articut-GraphQL 回傳結果2](../../Screenshots/Articut-GraphQL_Example02.png)



Expand Down

0 comments on commit c47d4b4

Please sign in to comment.