Simple program of Chinese lexical analysis

zhaozj2021-02-08  211

VC 6.0 compiles the phrase that via DISC dictionary express

// code.cpp: defines the entry point for the console application. //

#include "stdafx.h" #include "iostream.h" #include "string.h" #include "windows.h"

INT Countword (char * word); / / How many characters do you count?

Struct Dict {char SYN [8], Word [6]; int scode, wcode;} DIC [19];

INT Main (int Argc, char * argv []) {struct (DIC [0] .syn, "Praying verb"); DIC [0] .scode = 0; strcpy (DIC [0] .word, "please" ); DIC [0] .wcode = 0; STRCPY (DIC [1]. Syn, "Praying verb"); DIC [1] .scode = 0; STRCPY (DIC [1] .word, "put"); DIC [1] .wcode = 1; STRCPY (DIC [2]. Syn, "Pronoun"); DIC [2] .scode = 1; STRCPY (DIC [2] .word, "you"); DIC [2] .wcode = 0; STRCPY (DIC [3]. Syn, "verb"); DIC [3] .scode = 2; strcpy (DIC [3] .word, "walk"); DIC [3] .wcode = 0 STRCPY (DIC [4]. Syn, "verb"); DIC [4] .scode = 2; STRCPY (DIC [4] .word, "Run"); DIC [4] .wcode = 1; strcpy [5]. Syn, "verb"); DIC [5]. Scode = 2; Strcpy (DIC [5] .word, "Jump"); DIC [5] .wcode = 2; STRCPY (DIC [6]. SYN, "verb"); DIC [6] .scode = 2; STRCPY (DIC [6] .Word, "Turn"); DIC [6] .wcode = 3; strcpy (DIC [7] .syn, "verb "); DIC [7] .scode = 2; STRCPY (DIC [7] .word," Lift "); DIC [7] .wcode = 4; STRCPY (DIC [8] .syn," Direction Word "); DIC [8] .scode = 3; STRCPY (DIC [8] .word, "To Left"); DIC [8] .wcode = 0; STRCPY (DIC [9]. Syn, "Direction Word"); DIC [ 9]. Scode = 3; STRCPY (DIC [9] .word, "To Right"); DIC [9] .wcode = 1; STRCPY (DIC [10] .syn, "position"); DIC [10] .scode = 4; STRCPY (DIC [10] .word, "forward"); DIC [ 10] .wcode = 0; STRCPY (DIC [11] .Syn, "positioner"); DIC [11] .scode = 4; STRCPY (DIC [11] .word, "side"); DIC [11]. Wcode = 1; STRCPY (DIC [12] .syn, "noun"); DIC [12] .scode = 5; STRCPY (DIC [12] .word, "left hand"); DIC [12] .wcode = 0; STRCPY (DIC [13], "Noun"); DIC [13] .scode = 5; STRCPY (DIC [13] .Word, "Right-hand"); DIC [13] .wcode = 1; STRCPY (DIC [ 14]. Syn, "Noun"); DIC [14] .scode = 5; STRCPY (DIC [14] .word, "Left Leg"); DIC [14] .wcode = 2;

STRCPY (DIC [15]. Syn, "Noun"); DIC [15] .scode = 5; STRCPY (DIC [15] .word, "Right Leg"); DIC [15] .wcode = 3; STRCPY (DIC [16] .syn, "adverb"); DIC [16] .scode = 6; STRCPY (DIC [16] .Word, "Fast"); DIC [16] .wcode = 0; STRCPY (DIC [17]. SYN, "adverb"); DIC [17]. Scode = 6; STRCPY (DIC [17] .word, "slow"); DIC [17] .wcode = 1; strcpy (DIC [18] .syn, "other Word "); DIC [18]. Scode = 7; STRCPY (DIC [18] .word," Get up "); DIC [18] .wcode = 0; // - init data end /// char expression [30 ], phrase [40]; // Input sentence of the sentence Char * P1, * p2; // * PWORD PW_EXP1, PW_EXP2, PW_OLD; // Temp Pw_old can rollback int n_wordnub = 0, n_inputnub = 0; // * STRCPY (Expression, "Please quickly carry the left hand left leg"); for (int i = 0; i <40; i ) phrase [i] = ''; phrase [39] = '/ 0';

P2 = expression; p1 = phrase; pw_old = pw_exp1 = (pword) p2; // init

/ / Calculate the number of words input to determine the number of queries n_inputnub = countword (p2); Printf ("Analysis Result: / N");

For (int NUB = 0; NUB

IF ((char *) PW_EXP1! = P2) // Vocabula table Find word {for (int x = 0; x <((char *) PW_EXP1 - P2); x ) // Storage recognition word {* p1 = * ( P2 X); P1 ;} * p1 = '/'; // Fill in the separator P1 ; p2 = (char *) PW_EXP1; // Query the next PW_OLD = Pw_exp1; // can rollback}

IF (* p2 == '/ 0') // is over! {BREAK;}}}

// Query Dictionary! IF ((char *) PW_EXP1 == P2) && (* p2! = '/ 0')) // Nothing to find {cout << "不 {ou 不 <<"! "; Else {cout << "Identified!:"; cout << phrase;} return 0;}

INT Countword (Char * Words) {INT N = 0; While (* Words! = '/ 0') {Words ; N ;} Return Int (N / 2);

转载请注明原文地址:https://www.9cbs.com/read-2914.html

New Post(0)