Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1028602 // parseEnglishDateRange

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5429L/33K).

static LongRange parseEnglishDateRange(S s, DateInterpretationConfig config) {
  delegate Day to DateStructures.
  delegate Month to DateStructures.
  delegate Year to DateStructures.
  delegate Hour to DateStructures.
  delegate SomeDate to DateStructures.
  
  new EnglishDateParser parser;
  L<SomeDate> dates = getVars(parser.topDogs(s));
  
  print(+dates);
  if (empty(dates)) null;
  
  LongRange first = dateStructureToTimestampRange(first(dates), config);
  
  // check for combination of date & time, e.g. "tuesday between 1 and 2 pm"
  if (l(dates) == 2
    //&& first(dates) instanceof Day
    && !DateStructures.containsDateDates(second(dates))
    && DateStructures.containsTimes(second(dates))) {
    
    //Day day = cast first(dates);
    Day day = new Day(dayOfMonth(first.start), new Month(month(first.start), new Year(year(first.start))));
    SomeDate combined = cast defaultMetaTransformer().transform(o -> {
      //print("Visiting " + o);
      if (o cast Hour) ret cloneSetAll(o, +day);
      null;
    }, second(dates));
    print(+combined);
    ret dateStructureToTimestampRange(combined, config);
  }
    
  // just combine all the dates found
  ret joinLongRanges(map(d -> dateStructureToTimestampRange(d, config), dates));
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028602
Snippet name: parseEnglishDateRange
Eternal ID of this version: #1028602/15
Text MD5: fd49a177a9bce3d4d4229affc0fa02cb
Transpilation MD5: 3429c3e98560e5937f7ea2fa341a40b6
Author: stefan
Category: javax / english nlp
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-28 17:19:36
Source code size: 1289 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 235 / 353
Version history: 14 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)