public Search ( string inbuf, List |
||
inbuf | string | |
dm_r | List |
|
offsetList | List |
|
opertype | int | |
Результат | int |
public int Search(string inbuf, ref List<Lemma> dm_r, ref List<int> offsetList, int opertype)
{
int bpos = 0;
int pos = 0;
int nextpos = 0;
int nde = 0, lde = DM_DENTRY_FIRST;
int lmpos = DM_LEMMA_NULL;
int slemma = DM_LEMMA_NULL;
dm_r.Clear();
offsetList.Clear();
if (opertype == DM_OUT_FMM)
{
while (pos < inbuf.Length)
{
bpos = pos;
nextpos = pos + 1;
while (pos < inbuf.Length)
{
nde = SeekEntry(lde, inbuf[pos]);
if (nde == DM_DENTRY_NULL)
{
break;
}
lmpos = dentry[nde].lemma_pos;
if (lmpos != DM_LEMMA_NULL)
{
slemma = lmpos;
nextpos = pos + 1;
}
lde = nde;
pos++;
}
if (slemma != DM_LEMMA_NULL)
{
offsetList.Add(bpos);
dm_r.Add(lmlist[slemma]);
}
lde = DM_DENTRY_FIRST;
slemma = DM_LEMMA_NULL;
pos = nextpos;
}
}
else if (opertype == DM_OUT_ALL)
{
while (pos < inbuf.Length)
{
bpos = pos;
nextpos = pos + 1;
while (pos < inbuf.Length)
{
nde = SeekEntry(lde, inbuf[pos]);
if (nde == DM_DENTRY_NULL)
{
break;
}
lmpos = dentry[nde].lemma_pos;
if (lmpos != DM_LEMMA_NULL)
{
offsetList.Add(bpos);
dm_r.Add(lmlist[lmpos]);
}
lde = nde;
pos++;
}
lde = DM_DENTRY_FIRST;
pos = nextpos;
}
}
return 0;
}
//Read each line from strTextFileName, and verify wether terms in every line are in strDictFileName public static void Match(string strTextFileName, DictMatch match) { List<Lemma> dm_r = new List<Lemma>(); List<int> offsetList = new List<int>(); StreamReader sr = new StreamReader(strTextFileName); while (sr.EndOfStream == false) { string strLine = sr.ReadLine(); if (strLine.Length == 0) { continue; } dm_r.Clear(); offsetList.Clear(); match.Search(strLine, ref dm_r, ref offsetList, DictMatch.DM_OUT_FMM); //if dm_r.Count > 0, it means some contigous terms in strLine have matched terms in the dictionary. for (int i = 0; i < dm_r.Count; i++) { uint len = dm_r[i].len; int offset = offsetList[i]; string strProp = dm_r[i].strProp; string strTerm = strLine.Substring(offset, (int)len); Console.WriteLine("Matched term: {0}[offset:{1}, len:{2}, prop:{3}]", strTerm, offset, len, strProp); } } sr.Close(); }