Giter Site home page Giter Site logo

Comments (13)

anderscui avatar anderscui commented on May 27, 2024

嗯,后面想改进一下路径相关的问题,包括你说的这个问题,以及当前需要配置多个路径的问题,希望能够使配置更简单明了。请问有什么建议吗?

from jieba.net.

attsion avatar attsion commented on May 27, 2024

我临时是这么解决的:
`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.

anderscui avatar anderscui commented on May 27, 2024

@attsion 现在配置改成这样的了,只需要目录来配置:

<appSettings>
    <add key="JiebaConfigFileDir" value="C:\jiebanet\config" />
</appSettings>

from jieba.net.

attsion avatar attsion commented on May 27, 2024

回头试试,请问路径里面能填入相对路径吗?web下会不会又跑去找iisexpress的安装目录了?

from jieba.net.

anderscui avatar anderscui commented on May 27, 2024

@attsion Web的情况,相对路径还是那样会有问题,这次没有特别处理:)

如果你觉得有必要,下一次可以改成你的方式,通过AppDomain来找出当前应用所在的目录,适用于WinForm和Web应用。

from jieba.net.

attsion avatar attsion commented on May 27, 2024

恩恩 那就太感谢了,现在web是大势所趋啊。

from jieba.net.

alex521 avatar alex521 commented on May 27, 2024

web 下有处理的方法吗? 绝对路径在云服务器上没办法设。

from jieba.net.

anderscui avatar anderscui commented on May 27, 2024

@alex521 那么就像 @attsion 那样,用相对于AppDomain的路径了?

from jieba.net.

anderscui avatar anderscui commented on May 27, 2024

@attsion , @alex521 ,刚刚修改了,如果是相对路径,那么会使用相对于AppDomain的路径。

from jieba.net.

guxl avatar guxl commented on May 27, 2024

我的建议是,不考虑配置文件!原因如下:

  1. 客户端对Jieba.Net关于配置文件的需求各不相同,不能保证客户端的要求,就不如把权利交给客户端。
  2. 如果要支持.net Core, .net Core 的配置系统和现有方式完全不同,现在考虑这些会非常尴尬。
  3. 如果要将读取配置文件的任务放倒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.

anderscui avatar anderscui commented on May 27, 2024

@guxl 谢谢,你的建议很有帮助。我现在的工作已经是不用.NET了,对于.NET core虽然有兴趣,但恐怕没时间专门去学。感觉你对.NET是很熟悉的,能否帮忙做些这方面的开发?

from jieba.net.

sgf avatar sgf commented on May 27, 2024

@anderscui
与时俱进啊 老铁,支持.net core 大势所趋啊,而且其实 .net core 和.net framework 大部分没啥区别。

from jieba.net.

anderscui avatar anderscui commented on May 27, 2024

@guxl 现在可以直接通过代码设置了。

@sgf 已经同时支持net40和netstandard2.0。

from jieba.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.