当前位置:网站首页>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

TagDescription Description of meaning Example
rpronoun pronouns We
ngeneral noun Noun Apple
nsgeographical name Place names Beijing
wppunctuation punctuation ,.!
ksuffix suffix world , rate
hprefix Prefix o , false
uauxiliary auxiliary word Of , The earth
cconjunction Conjunction and , although
vverb Verb run , Study
ppreposition Preposition stay , hold
dadverb adverb very
qquantity quantifiers individual
nhperson name The person's name Du Fu , Tom
mnumber numeral One , First of all
eexclamation Statement label designator Ah
bother noun-modifier State words large , Western style
aadjective Adjective beautiful
nddirection noun Location words On the right side
nllocation noun Place words suburb
oonomatopoeia an onomatopoeia crash
nttemporal noun Time words In recent days, , Ming Dynasty
nzother proper noun Other proper names Nobel prize
nlorganization name Institutional groups The insurance company
iidiom Idiom flowers
jabbreviation Abbreviations Public prosecution
wsforeign words Loanwords CPU
gmorpheme Morpheme Katz , Nephew
xnon-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 :
 Insert picture description here

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 !
 Insert picture description here

原网站

版权声明
本文为[Deng_ Xian_ Sheng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202181327253398.html