
@prefix : <bud-aa#>.
@prefix str: <http://www.w3.org/2000/10/swap/string#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
     @prefix k: <http://opencyc.sourceforge.net/daml/cyc.daml#> .
     @prefix t: <http://www.w3.org/2000/10/swap/pim/travelTerms#> .
     @prefix iata: <http://www.daml.org/cgi-bin/airport?>.
     @prefix dt: <http://www.w3.org/2001/XMLSchema#> .

<> a k:ItineraryDocument;
  k:containsInformationAbout-Focally :thisTrip.

:thisTrip
  k:passengers <http://www.w3.org/People/Connolly/home-smart#me>;
  k:subEvents
    [ :desc "LV 16 May MCI at 1130AM to AR DFW at 105PM on 16 May" ],
    [ :desc "LV 16 May DFW at 255PM to AR ZRH at 755AM on 17 May"],
    [ :desc "LV 17 May ZRH at 1015AM to AR BUD at 1150AM on 17 May" ],
    [ :desc "LV 25 May BUD at 740AM to AR ZRH at 920AM on 25 May" ],
    [ :desc "LV 25 May ZRH at 1010AM to AR ORD at 1250PM on 25 May"],
    [ :desc "LV 25 May ORD at 248PM to AR MCI at 417PM on 25 May"].

##### scraping :desc

# departure date...
{ ?E :desc ?TXT.
  (?TXT "^LV (\\d\\d) May") str:scrape ?DD.
  ?DAY dt:date ?YMD.
  (?YMD "2003-05-(\\d\\d)") str:scrape ?DD.
} => { ?E k:startingDate ?DAY }.

# arrival date...
{ ?E :desc ?TXT.
  (?TXT "on (\\d\\d) May") str:scrape ?DD.
  ?DAY dt:date ?YMD.
  (?YMD "2003-05-(\\d\\d)") str:scrape ?DD.
} => { ?E k:endingDate ?DAY }.


@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix apt: <http://www.daml.org/2001/10/html/airport-ont#>.
this log:forAll :ACODE, :APT.

# airport of departure...
{
  ?E :desc ?TXT.
  (?TXT "^LV .. May (\\S\\S\\S) ") str:scrape :ACODE.

  ?APT_PG log:uri [ is str:concatenation of
	("http://www.daml.org/cgi-bin/airport?" :ACODE)].

  ?APT_PG log:semantics [ log:includes { :APT apt:iataCode :ACODE }].
} => {

#  ?E :__airportCode :ACODE.
#  ?E :__airportPage ?APT_PG.
  ?E k:fromLocation :APT
 }.



# time of departure...
:am :called "AM"; :offset "0".
:pm :called "PM"; :offset "12".
{
  ?E :desc ?TXT.
  (?TXT "^LV .. May \\S+ at (\\d?\\d)\\d\\d..") str:scrape ?HH.
  (?TXT "^LV .. May \\S+ at \\d?\\d(\\d\\d)..") str:scrape ?MM.
  (?TXT "^LV .. May \\S+ at \\d?\\d\\d\\d(..)") str:scrape ?AP.

  [ :called ?AP; :offset ?OFF].

  ([is math:sum of (?HH ?OFF)] ":" ?MM) str:concatenation ?HHMM.
} => { ?E t:departureTime ?HHMM }.


# airport of arrival...
{
  ?E :desc ?TXT.
  (?TXT "to AR (...) at") str:scrape :ACODE.

  ?APT_PG log:uri [ is str:concatenation of
	("http://www.daml.org/cgi-bin/airport?" :ACODE)].

  ?APT_PG log:semantics [ log:includes { :APT apt:iataCode :ACODE }].
} => {
  ?E k:toLocation :APT
}.

# time of arrival
:am :called "AM"; :offset "0".
:pm :called "PM"; :offset "12".
{
  ?E :desc ?TXT.
  (?TXT "AR \\S+ at (\\d\\d?)\\d\\d..") str:scrape ?HH.
  (?TXT "AR \\S+ at \\d\\d?(\\d\\d)..") str:scrape ?MM.
  (?TXT "AR \\S+ at \\d\\d?\\d\\d(..)") str:scrape ?AP.

  [ :called ?AP; :offset ?OFF].

  ([is math:sum of (?HH ?OFF)] ":" ?MM) str:concatenation ?HHMM.
} => { ?E t:arrivalTime ?HHMM }.



@prefix apt: <http://www.daml.org/2001/10/html/airport-ont#>.
{ ?WHERE a k:Airport-Physical; apt:name ?TXT } => { ?WHERE k:nameString ?TXT }.

:AA   a k:AirlineCompany;
         k:nameOfAgent "AMERICAN AIRLINES" .

#@@ make 2002/12/cal/weekDayRules.n3 ?
:_16MAY a k:Friday; dt:date "2003-05-16".
:_17MAY a k:Saturday; dt:date "2003-05-17".
:_25MAY a k:Sunday; dt:date "2003-05-25".
:_26MAY a k:Monday; dt:date "2003-05-26".
#@@ facts in 2002/12/cal/weekDayFacts.rdf?
k:Sunday a k:DayOfWeekType; k:nameString "Sunday".
k:Monday a k:DayOfWeekType;  k:nameString "Monday".
k:Friday a k:DayOfWeekType;  k:nameString "Friday".
k:Saturday a k:DayOfWeekType;  k:nameString "Saturday".

