Comments (13)
嗯,后面想改进一下路径相关的问题,包括你说的这个问题,以及当前需要配置多个路径的问题,希望能够使配置更简单明了。请问有什么建议吗?
from jieba.net.
我临时是这么解决的:
`using System.Configuration;
using System;
namespace JiebaNet.Segmenter
{
public class ConfigManager
{
public static string domin = AppDomain.CurrentDomain.BaseDirectory;
public static string MainDictFile
{
get { return domin + ConfigurationManager.AppSettings["MainDictFile"] ?? @"Resources\dict.txt"; }
}
public static string ProbTransFile
{
get { return domin + ConfigurationManager.AppSettings["ProbTransFile"] ?? @"Resources\prob_trans.json"; }
}
public static string ProbEmitFile
{
get { return domin + ConfigurationManager.AppSettings["ProbEmitFile"] ?? @"Resources\prob_emit.json"; }
}
public static string PosProbStartFile
{
get { return domin + ConfigurationManager.AppSettings["PosProbStartFile"] ?? @"Resources\pos_prob_start.json"; }
}
public static string PosProbTransFile
{
get { return domin + ConfigurationManager.AppSettings["PosProbTransFile"] ?? @"Resources\pos_prob_trans.json"; }
}
public static string PosProbEmitFile
{
get { return domin + ConfigurationManager.AppSettings["PosProbEmitFile"] ?? @"Resources\pos_prob_emit.json"; }
}
public static string CharStateTabFile
{
get { return domin + ConfigurationManager.AppSettings["CharStateTabFile"] ?? @"Resources\char_state_tab.json"; }
}
}
}`
建议仅对词典文件夹路径配置下就好,而且最好能在类的构造函数中提供一个重载来免配置文件的方式去处理词典路径。
from jieba.net.
@attsion 现在配置改成这样的了,只需要目录来配置:
<appSettings>
<add key="JiebaConfigFileDir" value="C:\jiebanet\config" />
</appSettings>
from jieba.net.
回头试试,请问路径里面能填入相对路径吗?web下会不会又跑去找iisexpress的安装目录了?
from jieba.net.
@attsion Web的情况,相对路径还是那样会有问题,这次没有特别处理:)
如果你觉得有必要,下一次可以改成你的方式,通过AppDomain来找出当前应用所在的目录,适用于WinForm和Web应用。
from jieba.net.
恩恩 那就太感谢了,现在web是大势所趋啊。
from jieba.net.
web 下有处理的方法吗? 绝对路径在云服务器上没办法设。
from jieba.net.
@alex521 那么就像 @attsion 那样,用相对于AppDomain的路径了?
from jieba.net.
@attsion , @alex521 ,刚刚修改了,如果是相对路径,那么会使用相对于AppDomain的路径。
from jieba.net.
我的建议是,不考虑配置文件!原因如下:
- 客户端对Jieba.Net关于配置文件的需求各不相同,不能保证客户端的要求,就不如把权利交给客户端。
- 如果要支持.net Core, .net Core 的配置系统和现有方式完全不同,现在考虑这些会非常尴尬。
- 如果要将读取配置文件的任务放倒JiaBa.net中,这就相当于分词组件干了它份外的事,不符合单一职责的设计原则,即便是想要帮助客户端多做一些事情,也应该以扩展或工具的形式,放到 `
JiebaSegmenter
之外,这样的话,如果扩展(或工具)类符合客户端的要求,客户端自己调用,如果不符合客户端的要求,客户端可以自己实现。
建议的方式:
任何需要外部资源(1)的地方,都提供便于客户端注入的接口(2),如果怕客户端会感到复杂,就提供一个JiebaSegmenterBuilder
生成器(3)。
(1)外部资源,包括词典、停用词、甚至是 todo.md 中所提到的 logging、cache等一些组件,最终目的就是实现 Ioc 和 Component化。
(2)建议上面提到的资源,以属性的方式由客户端注入,例如
public class JiebaSegmenter
{
public void UseDictPath(DirectoryInfo dictDir);
}
(3)如果参数实在是复杂,就弄一个builder,客户端调用如下:
public JiebaSegmenter BuildJiebaSegmenter()
{
return new JiebaSegmenterBuilder()
.WithDict.UseDefault()
.WithStopWords.FormFile(stopWrodsFile)
.WithLogger.UseConfig(logPosition, loglevel,etc)
.Build();
}
from jieba.net.
@guxl 谢谢,你的建议很有帮助。我现在的工作已经是不用.NET了,对于.NET core虽然有兴趣,但恐怕没时间专门去学。感觉你对.NET是很熟悉的,能否帮忙做些这方面的开发?
from jieba.net.
@anderscui
与时俱进啊 老铁,支持.net core 大势所趋啊,而且其实 .net core 和.net framework 大部分没啥区别。
from jieba.net.
@guxl 现在可以直接通过代码设置了。
@sgf 已经同时支持net40和netstandard2.0。
from jieba.net.
Related Issues (20)
- 如何启用 停用词库,感觉默认的好像没有去除停用词
- 请问自定义词库的方法可以多次调用么,还是说只能调用一次,多个自定义词库文件该如何处理呢? HOT 1
- .Net Core 3.1 LoadUserDict 下,會出現 Unhandled exception. System.UnauthorizedAccessException: Access to the path HOT 2
- 自定义字典中读取中文乱码导致不能匹配
- How to config the ConfigFileBaseDir in Abp framework HOT 2
- 自定义字典问题
- 请问支不支持VS2013
- newtonsoft.json.12.0.3 版本能不能降低成4.几?谢谢 HOT 2
- 今天4:50某某某领了一只记号笔中的4:50为什么不能识别成时间???
- 建议支持日期时间格式,不必拆分成为几个独立的数字,建议日期时间为完整的词
- AddWord
- 词性分析时调用自定义词典的方法 HOT 1
- 想邀请您的项目在 Gitee 同步代码并加入 dotNET China 组织(非微软官方)
- KeywordProcessor提词不准确
- highlighter返回结果问题
- 同义支持 HOT 2
- 不同分词实例加载不同字典怎么实现 HOT 4
- 有Net Core版本的使用示例吗
- JiebaNet.Segmenter是不是没用到停用词
- System.Text.Json 代替 Newtonsoft.Json
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jieba.net.