2 using System.Collections.Generic;
5 namespace NMeCab.Extension
7 public static class MeCabNodeExtension
12 public static string GetPartsOfSpeech(this MeCabNode node)
14 return GetCsvElement(node.Feature, 0);
20 public static string GetPartsOfSpeechSection1(this MeCabNode node)
22 return GetCsvElement(node.Feature, 1);
28 public static string GetPartsOfSpeechSection2(this MeCabNode node)
30 return GetCsvElement(node.Feature, 2);
36 public static string GetPartsOfSpeechSection3(this MeCabNode node)
38 return GetCsvElement(node.Feature, 3);
44 public static string GetConjugatedForm(this MeCabNode node)
46 return GetCsvElement(node.Feature, 4);
52 public static string GetInflection(this MeCabNode node)
54 return GetCsvElement(node.Feature, 5);
60 public static string GetOriginalForm(this MeCabNode node)
62 return GetCsvElement(node.Feature, 6);
68 public static string GetReading(this MeCabNode node)
70 return GetCsvElement(node.Feature, 7);
76 public static string GetPronounciation(this MeCabNode node)
78 return GetCsvElement(node.Feature, 8);
82 private unsafe static string GetCsvElement(string csvRow, int index)
84 if (string.IsNullOrEmpty(csvRow)) return null;
86 fixed (char* pCsvRow = csvRow)
87 return GetCsvElement(pCsvRow, csvRow.Length, index);
89 //string[] items = csvRow.Split(',');
90 //if (items.Length <= index) return null;
92 //return items[index];
95 private unsafe static string GetCsvElement(char* csvRow, int rowLength, int index)
97 char* end = csvRow + rowLength;
101 while (csvRow != end)
105 if (count == index) return new string(csvRow - len, 0, len);
113 return count == index ? new string(csvRow - len, 0, len) : null;