Skip to content

Commit

Permalink
新增了Mecab处理类库、SQL处理类库,修复了彩云翻译API错误;更新了README
Browse files Browse the repository at this point in the history
  • Loading branch information
hanmin0822 committed Mar 28, 2020
1 parent 75a6829 commit 6e3934c
Show file tree
Hide file tree
Showing 24 changed files with 1,075 additions and 532 deletions.
76 changes: 76 additions & 0 deletions MecabHelperLibrary/MecabHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using MeCab;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MecabHelperLibrary
{
public struct MecabWordInfo {

/// <summary>
/// 单词
/// </summary>
public string Word;

/// <summary>
/// 词性
/// </summary>
public string PartOfSpeech;

/// <summary>
/// 词性说明
/// </summary>
public string Description;

/// <summary>
/// Mecab能提供的关于这个词的详细信息 CSV表示
/// </summary>
public string Feature;
}


public class MecabHelper
{
private MeCabParam Parameter;
private MeCabTagger Tagger;

public MecabHelper() {
Parameter = new MeCabParam();
Tagger = MeCabTagger.Create(Parameter);
}


/// <summary>
/// 处理句子,对句子进行分词,得到结果
/// </summary>
/// <param name="sentence"></param>
/// <returns></returns>
public List<MecabWordInfo> SentenceHandle(string sentence) {

List<MecabWordInfo> ret = new List<MecabWordInfo>();

foreach (var node in Tagger.ParseToNodes(sentence))
{
if (node.CharType > 0)
{
var features = node.Feature.Split(',');

MecabWordInfo mwi = new MecabWordInfo {
Word = node.Surface,
PartOfSpeech = features[0],
Description = features[1],
Feature = node.Feature
};

ret.Add(mwi);
}
}

return ret;
}


}
}
73 changes: 73 additions & 0 deletions MecabHelperLibrary/MecabHelperLibrary.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.props" Condition="Exists('..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{82FDE770-321E-4433-8E05-8803850F24DB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MecabHelperLibrary</RootNamespace>
<AssemblyName>MecabHelperLibrary</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MeCab.DotNet, Version=0.0.26.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MeCab.DotNet.0.0.26\lib\net45\MeCab.DotNet.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MecabHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="dic\char.bin" />
<None Include="dic\dicrc" />
<None Include="dic\matrix.bin" />
<None Include="dic\sys.dic" />
<None Include="dic\unk.dic" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="dic\README.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.props'))" />
<Error Condition="!Exists('..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.targets'))" />
</Target>
<Import Project="..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.targets" Condition="Exists('..\packages\MeCab.DotNet.0.0.26\build\MeCab.DotNet.targets')" />
</Project>
36 changes: 36 additions & 0 deletions MecabHelperLibrary/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("MecabHelperLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MecabHelperLibrary")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("82fde770-321e-4433-8e05-8803850f24db")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
1 change: 1 addition & 0 deletions MecabHelperLibrary/dic/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains defaulted IPADIC files.
Binary file added MecabHelperLibrary/dic/char.bin
Binary file not shown.
29 changes: 29 additions & 0 deletions MecabHelperLibrary/dic/dicrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
;
; Configuration file of IPADIC
;
; $Id: dicrc,v 1.4 2006/04/08 06:41:36 taku-ku Exp $;
;
cost-factor = 800
bos-feature = BOS/EOS,*,*,*,*,*,*,*,*
eval-size = 8
unk-eval-size = 4
config-charset = SHIFT-JIS

; yomi
node-format-yomi = %pS%f[7]
unk-format-yomi = %M
eos-format-yomi = \n

; simple
node-format-simple = %m\t%F-[0,1,2,3]\n
eos-format-simple = EOS\n

; ChaSen
node-format-chasen = %m\t%f[7]\t%f[6]\t%F-[0,1,2,3]\t%f[4]\t%f[5]\n
unk-format-chasen = %m\t%m\t%m\t%F-[0,1,2,3]\t\t\n
eos-format-chasen = EOS\n

; ChaSen (include spaces)
node-format-chasen2 = %M\t%f[7]\t%f[6]\t%F-[0,1,2,3]\t%f[4]\t%f[5]\n
unk-format-chasen2 = %M\t%m\t%m\t%F-[0,1,2,3]\t\t\n
eos-format-chasen2 = EOS\n
Binary file added MecabHelperLibrary/dic/matrix.bin
Binary file not shown.
Binary file added MecabHelperLibrary/dic/sys.dic
Binary file not shown.
Binary file added MecabHelperLibrary/dic/unk.dic
Binary file not shown.
4 changes: 4 additions & 0 deletions MecabHelperLibrary/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MeCab.DotNet" version="0.0.26" targetFramework="net461" />
</packages>
Loading

0 comments on commit 6e3934c

Please sign in to comment.