当前位置:网站首页>PHP Chinese word segmentation API, Harbin Institute of technology ltpcloud, naturallanguageprocessing, free, best practices!
PHP Chinese word segmentation API, Harbin Institute of technology ltpcloud, naturallanguageprocessing, free, best practices!
2022-06-25 21:24:00 【Deng_ Xian_ Sheng】
I don't want to read the article ; Turn left out of the door , Natural language processing of Harbin Institute of technology :http://ltp.ai/index.html
Don't rush away , At the end of the article, there is someone who just came out of the pot PHP Code []
Request address :http://39.96.43.154:8080/api
// Don't doubt , This is this. ; Look broken , But it's easy to use. . Harbin Institute of technology api
Request type :POST
Content-Type: application/json
Parameters :{"text":" Text to be segmented ,1024 A word or 256 Within a word "}
return json: among ( Back to json)->words[0]->text It's participle ,( Back to json)->words[0]->pos Is part of speech , The second participle is followed by analogy ( Back to json)->words[1]->text ,( Back to json)->words[1]->pos
Example returned :
{
"text": " I'm dengwenyi , I am in Shenzhen, Guangdong !",
"nes": [
{
"text": " Deng Wenyi ",
"offset": 2,
"ne": "nh",
"length": 3
},
{
"text": " Guangdong shenzhen ",
"offset": 6,
"ne": "ns",
"length": 4
}
],
"words": [
{
"id": 0,
"length": 1,
"offset": 0,
"text": " I ",
"pos": "r",
"parent": 1,
"relation": "SBV",
"roles": [],
"parents": [
{
"parent": 1,
"relate": "EXP"
}
]
},
{
"id": 1,
"length": 1,
"offset": 1,
"text": " yes ",
"pos": "v",
"parent": -1,
"relation": "HED",
"roles": [
{
"text": " I ",
"offset": 0,
"length": 1,
"type": "A0"
},
{
"text": " Deng Wenyi ",
"offset": 2,
"length": 3,
"type": "A1"
}
],
"parents": [
{
"parent": -1,
"relate": "Root"
}
]
},
{
"id": 2,
"length": 3,
"offset": 2,
"text": " Deng Wenyi ",
"pos": "nh",
"parent": 1,
"relation": "VOB",
"roles": [],
"parents": [
{
"parent": 1,
"relate": "LINK"
}
]
},
{
"id": 3,
"length": 1,
"offset": 5,
"text": ",",
"pos": "wp",
"parent": 1,
"relation": "WP",
"roles": [],
"parents": [
{
"parent": 1,
"relate": "mPUNC"
}
]
},
{
"id": 4,
"length": 1,
"offset": 6,
"text": " I ",
"pos": "r",
"parent": 5,
"relation": "SBV",
"roles": [],
"parents": [
{
"parent": 5,
"relate": "EXP"
}
]
},
{
"id": 5,
"length": 1,
"offset": 7,
"text": " stay ",
"pos": "v",
"parent": 1,
"relation": "COO",
"roles": [
{
"text": " I ",
"offset": 6,
"length": 1,
"type": "A0"
},
{
"text": " Guangdong shenzhen ",
"offset": 8,
"length": 4,
"type": "A1"
}
],
"parents": [
{
"parent": 1,
"relate": "eSUCC"
}
]
},
{
"id": 6,
"length": 2,
"offset": 8,
"text": " guangdong ",
"pos": "ns",
"parent": 7,
"relation": "ATT",
"roles": [],
"parents": [
{
"parent": 5,
"relate": "LOC"
},
{
"parent": 7,
"relate": "FEAT"
}
]
},
{
"id": 7,
"length": 2,
"offset": 10,
"text": " Shenzhen ",
"pos": "ns",
"parent": 5,
"relation": "VOB",
"roles": [],
"parents": [
{
"parent": 5,
"relate": "LOC"
}
]
},
{
"id": 8,
"length": 1,
"offset": 12,
"text": "!",
"pos": "wp",
"parent": 1,
"relation": "WP",
"roles": [],
"parents": [
{
"parent": 5,
"relate": "mPUNC"
}
]
}
]
}
Part of speech marker set
Tag | Description | Description of meaning | Example |
---|---|---|---|
r | pronoun | pronouns | We |
n | general noun | Noun | Apple |
ns | geographical name | Place names | Beijing |
wp | punctuation | punctuation | ,.! |
k | suffix | suffix | world , rate |
h | prefix | Prefix | o , false |
u | auxiliary | auxiliary word | Of , The earth |
c | conjunction | Conjunction | and , although |
v | verb | Verb | run , Study |
p | preposition | Preposition | stay , hold |
d | adverb | adverb | very |
q | quantity | quantifiers | individual |
nh | person name | The person's name | Du Fu , Tom |
m | number | numeral | One , First of all |
e | exclamation | Statement label designator | Ah |
b | other noun-modifier | State words | large , Western style |
a | adjective | Adjective | beautiful |
nd | direction noun | Location words | On the right side |
nl | location noun | Place words | suburb |
o | onomatopoeia | an onomatopoeia | crash |
nt | temporal noun | Time words | In recent days, , Ming Dynasty |
nz | other proper noun | Other proper names | Nobel prize |
nl | organization name | Institutional groups | The insurance company |
i | idiom | Idiom | flowers |
j | abbreviation | Abbreviations | Public prosecution |
ws | foreign words | Loanwords | CPU |
g | morpheme | Morpheme | Katz , Nephew |
x | non-lexeme | Non lexical position | Grape , Soaring |
PHP call :
<?php
/** * send out post request * @param string $url Request address * @param array $post_data post Key value pair data * @return string */
function send_post2($url, $postdata) {
$options = array(
'http' => array(
'method' => 'POST',
'header' => array(
'Content-Type: application/json',
'Origin: http://ltp.ai',
'Host: 39.96.43.154:8080',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.3 Safari/605.1.15',
'Referer: http://ltp.ai/',
),
'content' => $postdata,
'timeout' => 15 * 60 // Timeout time ( Company :s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
// End of request
$typemsg = array('text'=>' I'm dengwenyi , I am in Shenzhen, Guangdong !');
$typemsg = json_encode($typemsg);// Convert an array to json
$value2 = send_post2('http://39.96.43.154:8080/api',$typemsg);
$value2 = json_decode($value2);// hold json Convert to object
foreach($value2->words as $value3){
// Traverse to get all participles
if($value3->pos != 'u' && $value3->pos != 'c' && $value3->pos != 'p'){
// exclude : auxiliary word , for example “ Of , The earth ”、 Conjunction , for example “ and , although ”、 Preposition , for example “ stay , hold ”
echo $value3->text;
echo '<br>';
}
}
Code results :
By the way , It's not advertising , IFLYTEK has cooperated with Harbin Institute of technology to establish “ Harbin Institute of technology - IFLYTEK language cloud ”,
Although stealing reading cannot be called stealing , But white whoring should have demeanor ; I just want to learn api How to use it is from Harbin Institute of technology , If the company wants to use it, it must be iFLYTEK , What if it breaks down .
All right. , This is the end of the article ; If you have any suggestions or do not understand ; Please leave a message in the comment area !
边栏推荐
- JS__ Prototype, prototype chain, call/apply__ Duyi
- 109 practical shell scripts
- 04 disk space management
- Is it safe to fry stocks with compass or securities software? Where can I open an account and how
- C language dynamic memory allocation
- Is it legal to open an account for flush stock trading software? Is it safe?
- STM32 self balancing robot project, with code, circuit diagram and other data attached at the end (learning materials and learning group at the end)
- CANoe. Diva operation guide - establishment of operation environment
- The robotframework executes CMD commands and bat scripts
- What is ARP (address resolution protocol)? (Powercert animated videos)
猜你喜欢
[nailing scenario capability package] exhibition admission
Rounding related calculation
Volatile qualifier
Openocd adds third-party device support: ht32f52352 Cortex-M0+
[nail scenario capability package] hospital visitor verification
Big end and small end
Sqlmap for interface security testing
Working principle and experimental analysis of DHCP
Install JDK, MySQL and nexus under Linux (tar package installation)
The beginning of manjaro's journey
随机推荐
A simple file searcher
How to solve the problem of flash write protection in STM32?
Cvpr2020 | the latest cvpr2020 papers are the first to see, with all download links attached!
Virtualenvwrapper solves the installation error, and virtualenvwrapper is permanently effective
[nailing - scenario capability package] nailer card
Data query of server SQL. The most important chapter in database learning
On dynamic programming
Command 'GCC' failed with exit status 1 when PIP install mysqlclient
Canoe learning notes (4)
The correct way to clear the cache of the computer. The computer will not get stuck immediately after changing. practical
[machine learning] machine learning from zero to mastery -- teaching you how to use decision tree to predict contact lens types
[nail scenario capability package] hospital visitor verification
Set eye color
Explain memcached principle in detail
[important notice] developer document update (12.13-12.19)
On merging and sorting
The beginning of manjaro's journey
C language: array with length 0
Illustration tcp/ip - Chapter 1 and 2 Notes
Robotframework rewrite framework add case control