OSDN Git Service

素性情報を取得する拡張メソッドを追加
authorkomutan <t_komuta@nifty.com>
Sun, 27 Jul 2014 12:13:04 +0000 (21:13 +0900)
committerkomutan <t_komuta@nifty.com>
Sun, 27 Jul 2014 12:13:04 +0000 (21:13 +0900)
src/LibNMeCabMMF/Extension/MeCabNodeExtension.cs [new file with mode: 0644]

diff --git a/src/LibNMeCabMMF/Extension/MeCabNodeExtension.cs b/src/LibNMeCabMMF/Extension/MeCabNodeExtension.cs
new file mode 100644 (file)
index 0000000..cbf1e77
--- /dev/null
@@ -0,0 +1,91 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+\r
+namespace NMeCab.Extension\r
+{\r
+    public static class MeCabNodeExtension\r
+    {\r
+        /// <summary>\r
+        /// 品詞を取得\r
+        /// </summary>\r
+        public static string GetPartsOfSpeech(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 0);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 品詞細分類1を取得\r
+        /// </summary>\r
+        public static string GetPartsOfSpeechSection1(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 1);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 品詞細分類2を取得\r
+        /// </summary>\r
+        public static string GetPartsOfSpeechSection2(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 品詞細分類3を取得\r
+        /// </summary>\r
+        public static string GetPartsOfSpeechSection3(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 3);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 活用形を取得\r
+        /// </summary>\r
+        public static string GetConjugatedForm(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 4);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 活用型を取得\r
+        /// </summary>\r
+        public static string GetInflection(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 5);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 活用型を取得\r
+        /// </summary>\r
+        public static string GetOriginalForm(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 6);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 読みを取得\r
+        /// </summary>\r
+        public static string GetReading(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 7);\r
+        }\r
+\r
+        /// <summary>\r
+        /// 発音を取得\r
+        /// </summary>\r
+        public static string GetPronounciation(this MeCabNode node)\r
+        {\r
+            return GetCsvElement(node.Feature, 8);\r
+        }\r
+\r
+        private static string GetCsvElement(string csvRow, int index)\r
+        {\r
+            if (string.IsNullOrEmpty(csvRow)) return null;\r
+\r
+            string[] items = csvRow.Split(',');\r
+            if (items.Length <= index) return null;\r
+\r
+            return items[index];\r
+        }\r
+    }\r
+}\r