Inform and Japanese

Hey, Good news everyone…

I think I have a better approach, having started from scratch. It seems that there was Japanese version of Zork released once upon on a time. When they ported it to the PS1, the engine they used had a spiffy Japanese interface. It had a context-aware verb system, along with a verb dictionary that you could use so you didn’t have to methodically type in text with a controller all the time.

I was able to dump the verb table, which had 171 entries in it. I can post if you want. The parser, when getting down to it, is pretty simple. The grammar worked by having a few predefined sentence structures and picking out the relevant nominals, adjectivals, and verbals. Adjectivals and nominals were parsed as a single unit, so it’s a simple Object-Verb parser with lots of syntax sugar sprinkled in.

It has predefined syntax for the following.
“Verb the Object” (Object o Verb) [default] ex. “Take the ball”
“Verb the Object to/in/on the Subject” (Object o Subject ni Verb) ex. “Give the ball to the dog”
“Verb the Object from the Subject” (Object o Subject kara Verb) ex. “Untie the rope from the post”
“Verb the Object and the Object” (Object to Object o Verb) ex, “Take the axe and plate”
“Verb the Object with the Subject” (Object o Subject de Verb) ex. “Dig the hole with the shovel”
“Verb the Subject with the Object” (Subject de Object o Verb) ex. “Turn the bolt with the wrench”

There are a few nominal-based edge cases such as “Get all”, “Get all except”. I only ran across one context case which is:
“Light the candle on fire with the match”
However the parser accepts the “Light on fire” as the verb-part and parses it as such
Subject de Object ni “hi wo tsukeru”

All in all, it doesn’t look that terrible at all can be broken down with simple expression matching… Of course I can speak too soon. :stuck_out_tongue:

…and I hit my first issue of the day.

Here’s the gameplan.
What I’m planning on doing is override the two rules used for communicating to other people, and then place my text-string replacement code there.

Persuasion was easy

Persuasion rule for asking Kaori to try doing something:
	say "何?[line break]";
	persuasion fails.

That effectively blocks any command from reaching that character. That’ll keep her from understanding English in the form of implicit commands. Now the next thing is to override the “Name, [some text]” system.
Turning actions on, I feed the parser a bogus command.

>kaori, pen o totte.
[answering Kaori that "pen o totte ."]
There is no reply.
[answering Kaori that "pen o totte ." - succeeded]

So it’s defaulting to the “Answering [something] that [some text]” rule
So cool so far, I can use [some text] as the basis of my Japanese parser, but I can’t seem to figure out how to do a “Instead of answering Kaori anything:” and then saying something like “jcommand is [some text]” so I can then start in on the string searches.

The idea is that I will search out the common Japanese sentence structures and generate my own commands in English, and “push” those to kaori as as a “try”.

The simplest answer is:

Instead of answering:
	say "You said '[the topic understood]'."

But if you want to do a lot of string manipulation on the text, you probably want it as an indexed-text value:

Instead of answering:
	let T be indexed text;
	now T is the topic understood;
	say "You said '[T]'.";

You can then start messing with T using the techniques described in chapter 19.

I came up with the same solution. :slight_smile: I’m getting better at this…

On of the “problems” with Inform is that it’s super easy to over-complicate your problems when a simple elegant solution exists. On top of that, because the answer is literally in plain English, it just makes you feel dumb.

I come from a C# world where the computing concepts are the same, but handling them is widely different. I keep seeing objects as instantiated classes, and then thinking about hierarchy, parent child relationships, and inheritance in general. I need to stop “thinking like a programmer”. It taxes the braincells when you are trying to see the matrix-like green text waterfalls, when you should be looking at the girl in the red dress.

Just a small update

I got Inform to understand and output a coherent Japanese sentence. I’m so happy I can just cry :slight_smile:


In case anyone is wondering, I have a blog about writing my game in inform… You can read it here.

Another update!

I know, once again a screenshot, but the parser is now (kinda) working
It understands politeness levels, and different forms of auxiliary verbs, and also does not understand English or nonsense.

The edge-casing doesn’t work, the nominal lookups are broken, and the grammar checking is non-existent, but I was able to get though the entire parsing complex and get intelligible results. It can only improve from here.

Happy Easter!

Hmm. The way the parser works is that it first tokenises the input, building an array of words and their positions in the input. I wonder if you could jump in very early and reverse the order of that array. That might then let the parser operate normally, rather than you having to build your own.

Zarf, do you think that could work?

You’d have to reverse the input buffer as well – that is, reverse it word-wise. The parser wants the token array to be in the same order as the buffer, so that disambiguation can paste stuff in sensibly.

This is easy enough to do, but I haven’t been following the discussion of Japanese syntax well enough to know if it’s what halkun really needs.

No, it’s a little more than just parsing in reverse. The reason why I’m doing in that way is because of a nuance where Japanese verbs just happen to be at the end of phrases. Objects are actually in the middle while phrase subjects are at the beginning like in English. In Japanese, subjects are dropped if the context is understood. When I talk about edge casing in my blog, I’m talking about certain verbs that require both a subject and an object. “Tie” is an example of this. (Tie the rope to the tree). This will require the parser to find the particle markers and tolkenize the subject and object. In some instances, such as “turn” the subject and object can be reversed. The will require finding the particles so that the wrench turns the bolt, while the the bolt is turned by the wrench.

Also keep in mind that adjectives still come before the noun in Japanese too, but can be tensed. Also, japanese adverbs go before the verb not after.

I’m doing away with much of the grammar rules by implementing requests only. I’m even droping a good chunk of politeness levels but they may wiggle back in again. It depends on how much weight the parser can bear. As the goal of the game is to teach Japanese, its a core componant to conversation. It is also a videogame after all, so super polite phrases may be dropped as a design desision.

Also some of the conversation/exposition will be handeled by scenes and events, bypassing the request parser and using something different, all togeather.

What you’re calling a subject is actually an object (or maybe an indirect object). Inform has support built in for swapping the order of those. And as far as I know it won’t care about the order of adjectives, because it doesn’t actually have the concept. Probably most of the time the particles could just be ignored too. Keep going with your current approach, but if you get into trouble I bet you could get 90% there by swapping the order of the parse buffer.

fixed the ability to parse nouns now… It’s getting better :slight_smile:

Double post, but I have a new update.

This is pretty much the parser in it’s current state. It’s not perfect, but it’s now officially deemed “stable” so I can now move on to another part of the game.

The parser itself has both entry and exit sanity checks. It can promote auxiliary verbs. It can tell if you write too little or or much, and check against it’s own Japanese dictionary to make sure that you aren’t writing gibberish Japanese. There is also very weak grammar checking. It’s not perfect, but it works.

As you can tell from the example, I use “Kudasai” as both a primary and aux verb, and I pre-scripted a response when I try and kiss Kaori. You can also see we can pass things back and forth between each other’s inventory. That’s going to be a big thing in the game as far as solving puzzles.

I have a spot for edge-casing single word responses, and also more complex sentences, but have left them unimplemented for now. The reason why is because they will be pretty easy to implement in this framework, and I don’t know which edge cases I’ll be using in the game yet.

I’m moving on to building my GUI in Glimmr now. I’m also going to start doing some old fashioned worldbuilding. I’ll keep everyone posted.

Looks nice! I would have totally forgotten about 名詞を下さい.