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).

1  
static LongRange parseEnglishDateRange(S s, DateInterpretationConfig config) {
2  
  delegate Day to DateStructures.
3  
  delegate Month to DateStructures.
4  
  delegate Year to DateStructures.
5  
  delegate Hour to DateStructures.
6  
  delegate SomeDate to DateStructures.
7  
  
8  
  new EnglishDateParser parser;
9  
  L<SomeDate> dates = getVars(parser.topDogs(s));
10  
  
11  
  print(+dates);
12  
  if (empty(dates)) null;
13  
  
14  
  LongRange first = dateStructureToTimestampRange(first(dates), config);
15  
  
16  
  // check for combination of date & time, e.g. "tuesday between 1 and 2 pm"
17  
  if (l(dates) == 2
18  
    //&& first(dates) instanceof Day
19  
    && !DateStructures.containsDateDates(second(dates))
20  
    && DateStructures.containsTimes(second(dates))) {
21  
    
22  
    //Day day = cast first(dates);
23  
    Day day = new Day(dayOfMonth(first.start), new Month(month(first.start), new Year(year(first.start))));
24  
    SomeDate combined = cast defaultMetaTransformer().transform(o -> {
25  
      //print("Visiting " + o);
26  
      if (o cast Hour) ret cloneSetAll(o, +day);
27  
      null;
28  
    }, second(dates));
29  
    print(+combined);
30  
    ret dateStructureToTimestampRange(combined, config);
31  
  }
32  
    
33  
  // just combine all the dates found
34  
  ret joinLongRanges(map(d -> dateStructureToTimestampRange(d, config), dates));
35  
}

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: 157 / 255
Version history: 14 change(s)
Referenced in: [show references]