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

68
LINES

< > BotCompany Repo | #1027975 // test_RecursiveProbabilisticParser1

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

Libraryless. Click here for Pure Java version (7884L/53K).

svoid test_RecursiveProbabilisticParser1() {
  new RecursiveProbabilisticParser1 p;
  p.requireQuotedProductions = false;
  p.loadRules("<thing> has a <thing> => <sentence> => has($1, $2)");
  assertEqualsVerbose(ll([[has("the farmer", "pig")]]),
    p.parse("the farmer has a pig"));
    test_RecursiveProbabilisticParser1_2();
}

svoid test_RecursiveProbabilisticParser1_2() {
  new RecursiveProbabilisticParser1 p;
  p.loadRules([[
    "Ein/eine/der/die/das <ding> führt (nach/in/hin zu/ins) <ort>" => satz => $1 leads to $2
    "zimmer <zimmername>" => zimmer => room $1
    "der/die/dem/das/den <nomen>" => nomen => the $1
  ]]);
  p.sentenceClass = "satz";
  p.useRoundBrackets = true;
  assertEqualsVerbose(ll("(Haustür) leads to (the (room (Flur)))"), p.parse("Die Haustür führt in das Zimmer Flur"));
  
  test_RecursiveProbabilisticParser1_3();
}

svoid test_RecursiveProbabilisticParser1_3() {
  new RecursiveProbabilisticParser1 p;
  p.loadRules([[
    "vom/... <ort> kommt/gelangt man <füller> in/nach/... <ort>" => satz => $1 connects to $2
    "zimmer <zimmername>" => zimmer => room $1
    "der/die/dem/das/den <nomen>" => nomen => the $1
  ]]);
  p.sentenceClass = "satz";
  p.useRoundBrackets = true;
  assertEqualsVerbose(ll("(Flur) connects to (the (room (GästeWC)))"), p.parse("Vom Flur kommt man (auch) in das Zimmer GästeWC"));
  
  test_RecursiveProbabilisticParser1_4();
}

svoid test_RecursiveProbabilisticParser1_4() {
  new RecursiveProbabilisticParser1 p;
  p.loadRules([[
    "Ein/eine/der/die/das <ding> führt (nach/in/hin zu/ins) <ort>" => satz => $1 leads to $2
    "Ein/eine/der/die/das <ding> führt von/vom <ort> (nach/in/hin zu/ins) <ort>" => satz => $1 leads from $2 to $3
    "Ein/eine/der/die/das <ding> führt von/vom <ort> nach <ort> (in/hin zu/ins) <ort>" => satz => $1 leads from $2 to $3 to $4
    "der/die/dem/das/den <nomen>" => nomen => the $1
    "der/die/dem/das/den <nomen> des/der <nomen>" => nomen => $1 of $2
    "<ding> in/im <ort>" => ding => $1 in $2
    "erster/erste/ersten <nomen>" => nomen => first $1
    "zimmer <zimmername>" => zimmer => room $1
    zimmer => ort
    ding => nomen
    ort => nomen
    bereich => ort
   "auch <nomen>" => nomen => also $1
    "ein/eine/einen/einem <nomen>" => nomen => a $1
    "kein/keine/keinen/keinem <nomen>" => nomen => no $1
    "bereich <bereichsname>" => bereich => area $1
    "der/... <ding> zwischen <ort> und <ort>" => ding => the $1 between $2 and $3
    "<ding> geht <füller> nach <richtung> auf" => satz => $1 opens to the $2
    "<nomen> und <nomen>" => nomen => $1 and $2
    "vom/... <ort> kommt/gelangt man <füller> in/nach/... <ort>" => satz => $1 connects to $2
    "von da aus kommt/gelangt man <füller> in/nach/... <ort>" => satz => last mentioned place connects to $1
    "<nomen> hat <füller> <nomen>" => satz => $1 has $2
    "<nomen> hat <füller> einen Bereich <nomen>" => satz => $1 has an area $2
  ]]);
  p.sentenceClass = "satz";
  p.useRoundBrackets = true;
  assertEqualsVerbose(ll("(the (room (Hauptkeller))) has (a (area (Heizungsanlage)))"), p.parse("Das Zimmer Hauptkeller hat einen Bereich Heizungsanlage"));
}

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: #1027975
Snippet name: test_RecursiveProbabilisticParser1
Eternal ID of this version: #1027975/17
Text MD5: 519eff9e95e29386154bda23d09fcd8d
Transpilation MD5: 274c3f209a3af2de0bb7f95b445a7739
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-23 12:04:06
Source code size: 3226 bytes / 68 lines
Pitched / IR pitched: No / No
Views / Downloads: 250 / 462
Version history: 16 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)