Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Implication is not enough

by PetaMem (Priest)
on Jul 29, 2001 at 12:02 UTC ( [id://100657]=perlmeditation: print w/replies, xml ) Need Help??

Fellow Monks,

intentionally this goes to Meditation and not to "Seekers".
As we all know (or at least as Fatvamp thinks :-)) a simple
if clause does the magic of implication:

IF <ANALYZE> -> <GENERATE>
Now for the application I´m doing right now (some NLP just
for fun), ANALYZE and GENERATE could really
need to be interchanged (used both ways). I´ll try to
explain with some examples:

Consider the german language. A simple subset of rules
could be:

Word (male, singular) <-> Word + Suffix "in" (female,singular)
and
Word (female, singular) <-> Word + Suffix "en" (female, plural)
So now, consider those words: Ägypter (Egyptian), Ägypterin
(female Egyptian), Ägypterinen (female Egyptians). Ideally
one should be able to pass any of these 3 words to a "rule-
processor" containing only the 2 above mentioned rules to
get them analyzed. (And of course having in each case any of
the other 2 words being generated - if in "generating-mode")

The only alternative I see at the moment is to have 4 IF
tests instead of those 2 rules. And there is much redundancy
in them. And I´m so lazy. :-) And because I´m so lazy, I state
that the 4 IF solution is unelegant.

IF Word (male, singular) -> Word + Suffix "in" (female,singular)
IF Word + Suffix "in" (female,singular) -> Word (male, singular)
IF Word (female, singular) -> Word + Suffix "en" (female, plural)
IF Word + Suffix "en" (female, plural) -> Word (female, singular)
It really is. Don´t you think? Any thoughts on this?

Ciao

Replies are listed 'Best First'.
Re: Implication is not enough
by tadman (Prior) on Jul 30, 2001 at 07:35 UTC
    My first thought is that perhaps you are using your logic backwards. Instead of progressing through a list of possibilities, it might be better to test in reverse.

    Admittedly my familiarity with German is limited to reading road signs and asking the border guards if we were entering or leaving Germany, as winding through the alps along the border you can lose track of that sort of thing, the road following geography more than political boundaries.

    Maybe what you are saying is this:
    $g = "m"; $q = "singular"; if ($word =~ /en$/) { $g = "f"; $q = "plural" if ($word =~ /inen$/); }
    Of course, I am just condensing your logic here.

    The big question is "Where are you going with this?", because that will have a large bearing on the sophistication of your methodology.
      I might be missing the boat here, but "Ägypterinen" would match both if statements, meaning at the end you would have $g = "f", $q = "plural", which I can only presume is the intent of the exercise.

      Like you pointed out, though, this is just a bunch of if statements, and goes one way only.

      However, you really haven't given any idea as to where you're going with this, other than some loose hints. Are you trying to write a parser for German, or a sub-set of German, or a parser that can work on any language, including German. The scope is important.

      First, I would try and express the rules in Perl using some sort of data structure. In many cases, the design of your algorithm can come straight from your data design. In others, it is the other way around. Either way, you have to start somewhere, so if you have no idea how to implement it, at least you can describe it.
      Hi,

      That way, you stil have *only* implication but changed
      the precedence of some steps (badly). Look:

      If the word you get to test would be "Ägypterinen", you
      never would come to the guts of if($word =~ /en$/)

      Ok. Where am I going with this? Well - theres no correct
      or complete morphological parser of the german language as
      of today. I could write one, but I would like to write it
      elegantly. Seems I´m missing a feature in Perl. Or just
      some decent way to craft code that can potentially both
      analyze and generate.

      The task is easy.
      
      Given 3 german words. Ägypter, Ägypterin, Ägypterinen
      
      Write a routine that takes a list of 3 Arguments:
      word, genus, numerus.
      
      and returns a list of 3 elements:
      word, genus, numerus
      
      where "word" is the word that was given to the routine
      after applying genus and numerus to it.
      genus and numerus are the genus and numerus the word HAD
      BEFORE applying the new genus and numerus to it.
      
      Like so:
      sub mystical_de_morphology_ruleprocessor { my $word = shift; my $new_genus = shift; my $new_numerus = shift; TRY_RULE1: (word (m,sg) <-> word + "in" (f, sg)) TRY_RULE2: (word (f,sg) <-> word + "en" (f,pl)) return newword, old_gen, old_num; }
      The TRY_RULE part is it. I just want to apply rules
      2 rules = 4 IFs, 3 rules = 8 IFs, 10 rules = forget it.
      Prolog would be nice, but I want stick with perl for that.

      Ciao

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://100657]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-28 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found