开发者

Fuzzy date/time management library for .NET

I am searching for a .NET library that can store and manage fuzzy (i.e. uncertain) dates/times, that is, temporal expressions that do not follow the usual precise pattern of day, month, year, hour, minute, second. I need something that can handle date/time values expressed开发者_StackOverflow中文版, for example, as:

  • Second quarter of 1985
  • Early 1930s
  • Second third of the XVII century

The library would probably implement a FuzzyDateTime type or something like that, and allow multiple ways to construct instances of it from text and/or regular DateTime values. Comparison and sorting features are also required.

So, my question is: do you know of any available products that fit this description? I am happy to consider all sorts of products, i.e. commercial, open source, freeware, etc.

Any ideas? Many thanks.


You'll likely have to code this from scratch. There may be a Java library that you could convert, but it seems this type of functionality is a thing of academia right now, rather than something being in production various places. In the end you may be able to use something academic, but you'll probably have to code your own based on your need.

To allow greatest flexibility, I would store each part of the date in separate nullable fields, with a value indicating the uncertainty of the first null field.

class UncertainDate
{
    public byte? Millennium { get; set; }
    public byte? Century { get; set; }
    public byte? Decade { get; set; }
    public byte? Year { get; set; }
    public byte? Month { get; set; }
    public byte? Day { get; set; }
    // more as you see fit

    public decimal Uncertainty { get; set; }
}

As an example, "first quarter of 2000" would be represented as:

var d = new UncertainDate() { Millennium = 2, Century = 0, Decade = 0, Year = 0, Uncertainty = 0.25m };

That leaves you a long route to travel as far as parsing string input and giving string output, but it makes comparisons easy (compare each field in order, first or lowest uncertainty loses).

You could also use an enumeration for the uncertainty, maybe values like FirstQuarter, FirstHalf, Early, Late, ThirdQuarter, etc. Decimal makes relative comparisons easy, but harder to back convert to things like "second half" (i.e. would 0.75 be "second half" or "third quarter" ?)

For reference, there have been similar questions asked.


I don't know of any library/product although I can imagine that this point has been at least thought about in any of the "semantic" fields (like semantic web etc.).

IF I undestand corectly what you are after (esp. when you want to sort etc.) then those "fuzzy" things are just "intervals" between two specific points in time...

You could create a class containing 2 DateTimes... Start and End... alternatively a Start plus duration...
Add to that whatever representation you might imagine... Some constructors to interpret what you want to throw at them (like something that "knows" what "early" or "quarter" means) and builds the relevant start and end from that.

Since you have a start DateTime and an end (either DateTime or a duration) these are perfectly comparable and sortable...

As for storing you could make it serializable...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜