1 // MeCab -- Yet Another Part-of-Speech and Morphological Analyzer
3 // Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
4 // Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
6 using System.Collections.Generic;
12 public class CharProperty
14 #region Const/Field/Property
16 private const string CharPropertyFile = "char.bin";
18 private string[] cList;
20 private readonly CharInfo[] charInfoList = new CharInfo[0xFFFF];
24 get { return this.cList.Length; }
31 public void Open(string dicDir)
33 string fileName = Path.Combine(dicDir, CharPropertyFile);
35 using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
36 using (var reader = new BinaryReader(stream))
38 this.Open(reader, fileName);
42 public void Open(BinaryReader reader, string fileName = null)
44 uint cSize = reader.ReadUInt32();
46 if (reader.BaseStream.CanSeek)
48 long fSize = sizeof(uint) + 32 * cSize + sizeof(uint) * charInfoList.Length;
49 if (reader.BaseStream.Length != fSize)
50 throw new MeCabInvalidFileException("invalid file size", fileName);
53 this.cList = new string[cSize];
54 for (int i = 0; i < this.cList.Length; i++)
56 this.cList[i] = StrUtils.GetString(reader.ReadBytes(32), Encoding.ASCII);
59 for (int i = 0; i < this.charInfoList.Length; i++)
61 this.charInfoList[i] = new CharInfo(reader.ReadUInt32());
67 #region Get Infometion
69 public string Name(int i)
74 public unsafe char* SeekToOtherType(char* begin, char* end, CharInfo c, CharInfo* fail, int* cLen)
79 *fail = this.GetCharInfo(*p);
81 while (p != end && c.IsKindOf(*fail))
87 *fail = this.GetCharInfo(*p);
93 public CharInfo GetCharInfo(char c)
95 return this.charInfoList[c];