- input 詩を書く
- output 詩があなたを書く
Last active
August 29, 2015 13:57
-
-
Save otya128/9871523 to your computer and use it in GitHub Desktop.
ANATA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using NMeCab; | |
namespace touch | |
{ | |
public static class Program | |
{ | |
static System.Collections.Generic.IEnumerable<MeCabNode> mecabutil(MeCabNode node) | |
{ | |
while (node != null) | |
{ | |
yield return node; | |
node = node.Next; | |
} | |
} | |
public static string touch(string sentence) | |
{ | |
string result = ""; | |
MeCabParam param = new MeCabParam(); | |
param.DicDir = @"D:\Visual Studio 2013\Projects\touch\touch\NMeCab\dic\ipadic";//@"..\..\NMeCab\dic\ipadic"; | |
MeCabTagger t = MeCabTagger.Create(param); | |
MeCabNode node = t.ParseToNode(sentence); | |
List<MeCabNode> target = new List<MeCabNode>(); //詩を書く | |
// ^^ | |
//List<MeCabNode> target2 = new List<MeCabNode>();//詩を書く | |
// ^^^^ | |
MeCabNode girl = null; | |
//詩があなた[を]書く | |
while (node != null) | |
{ | |
if (node.CharType > 0) | |
{ | |
//Console.WriteLine(node.Surface + "\t" + node.Feature); | |
if (node.Feature.IndexOf("助詞") != -1) girl = node; | |
target.Add(node);//else if (girl == null) target.Add(node); else target2.Add(node); | |
} | |
node = node.Next; | |
} | |
foreach (var i in target) | |
{ | |
if (i == girl) result += ("があなた"); | |
result+=(i.Surface); | |
}/* | |
result+=("があなた"); | |
result+=(girl.Surface); | |
foreach (var i in target2) | |
{ | |
result+=(i.Surface); | |
}*/ | |
t = MeCabTagger.Create(param); | |
MeCabNode node2 = t.ParseToNode(result); | |
int index = 0; | |
int gan = - 1; | |
MeCabNode prev = null; | |
foreach (var i in mecabutil(node2)) | |
{ | |
if(i.Surface == "が") | |
{ | |
if(gan + 2 == index) | |
{ | |
i.Surface = "と"; | |
} | |
gan = index; | |
prev = i; | |
} | |
if (i.Surface == "は") | |
{ | |
if (gan + 2 == index) | |
{ | |
prev.Surface = "と"; | |
} | |
} | |
index++; | |
} | |
var res2 = result; | |
result = ""; | |
foreach (var i in mecabutil(node2)) | |
{ | |
result += res2 == i.Surface ? "" : i.Surface; | |
} | |
return result; | |
} | |
/// <summary> | |
/// アプリケーションのメイン エントリ ポイントです。 | |
/// </summary> | |
[STAThread] | |
static void Main() | |
{ | |
while (true) | |
{ | |
Console.WriteLine(touch(Console.ReadLine())); | |
} | |
Application.EnableVisualStyles(); | |
Application.SetCompatibleTextRenderingDefault(false); | |
Application.Run(new Form1()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment