Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 919977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:37:56+00:00 2026-05-15T18:37:56+00:00

I am creating a program that will fill in a given grammar. Right now

  • 0

I am creating a program that will fill in a given grammar. Right now I am modeling the “kinds of words” like this:

public class WordDescriptor {

    public static final String noun = "N";
    public static final String plural = "p";
    public static final String nounPhrase = "h";
    public static final String usuParticipleVerb = "V";
    public static final String transitiveVerb = "t";
    public static final String intransitiveVerb = "i";
    public static final String adjective = "A";
    public static final String adverb = "v";
    public static final String conjunction = "C";
    public static final String preposition = "P";
    public static final String interjection = "!";
    public static final String pronoun = "r";
    public static final String definiteArticle = "D";
    public static final String indefiniteArticle = "I";
    public static final String nominative = "o";
    public static final String defaultTag = "?";

    private String word; // where word is one of the constants defined above.  

    public String getWord(){
        return word;
    }

    public String setWord(){
        return word;
    }

    /** For debugging only.  
     * 
     * @param s
     * @return
     */
    protected static String getKind(String s){
        if(s.equals(noun)){
            return "noun";
        }else if(s.equals(plural)){
            return "plural";
        }else if(s.equals(nounPhrase)){
            return "nounPhrase";
        }else if(s.equals(usuParticipleVerb)){
            return "usuParticipleVerb";
        }else if(s.equals(transitiveVerb)){
            return "transitiveVerb";
        }else if(s.equals(intransitiveVerb)){
            return "intransitiveVerb";
        }else if(s.equals(adjective)){
            return "adjective";
        }else if(s.equals(adverb)){
            return "adverb";
        }else if(s.equals(conjunction)){
            return "conjunction";
        }else if(s.equals(preposition)){
            return "preposition";
        }else if(s.equals(interjection)){
            return "interjection";
        }else if(s.equals(pronoun)){
            return "pronoun";
        }else if(s.equals(definiteArticle)){
            return "definiteArticle";
        }else if(s.equals(indefiniteArticle)){
            return "indefiniteArticle";
        }else if(s.equals(nominative)){
            return "nominative";
        } else if(s.equals(defaultTag)){
            return "defaultTag";
        }else{
            return "other: "+s;
        }
    }

}

This is pretty much the most ugly code that I can imagine. I know I can make it a bit better by using a case statement however that is still friggin ugly. Here is my question:

How can I make it beautiful? I was thinking about making:

  • class WordDescriptor, with subclasses:
    • class noun, with subclasses:
      • singular
      • plural
    • class verb
    • class adverb

But I am not sure if this seems like a great idea either. How can I this out better?


Edit: If I did take the second approach I am not even sure what the classes would look like. Here is an example:

public abstract class WordDescriptor {

   public String toString();

}

public class Noun extends WordDescriptor {

    public String toString(){
        return "Noun";
    }
}

public class Plural extends Noun{
    public String toString(){
        return "Plural";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:37:57+00:00Added an answer on May 15, 2026 at 6:37 pm

    You could do something with an enumerated type.

    public enum SpeechPart
    {
        NOUN ("noun"),
        PLURAL ("plural"),
        NOUNPHRASE ("noun phrase"),
        ADVERB ("adverb"),
        ADJECTIVE ("adjective"),
        CONJUNCTION ("conjunction"),
        VERB ("verb");
    
        private String english;
    
        SpeechPart(String inEnglish)
        {
            this.english = inEnglish;
        }
    
        public String toString() { return english; }
    }
    

    You can now assign these to a variable.

    SpeechPart dog = SpeechPart.NOUN;
    SpeechPart ran = SpeechPart.VERB;
    SpeechPart quickly = SpeechPart.ADVERB;
    

    And then you can see what their parts of speech are:

    System.out.println(dog.toString());
    System.out.println(quickly);        // Implicit call to toString()
    

    This solution assumes only a single part of speech per word. To allow for modifiers, such as “first person,” “third person,” “plural,” “present,” “progressive,” etc., you could simply enumerate all of them — a tedious job but need be done only once. Alternatively, you could adapt the Decorator Pattern, which addresses specifically the need to add attributes to an object dynamically.

    Another suggestion is enumerate the modifiers:

    public enum SpeechModifier
    {
        SINGULAR,
        PLURAL,
        FIRST_PERSON,
        SECOND_PERSON,
        THIRD_PERSON,
        PRESENT,
        PAST,
        PERFECT,
        PROGRESSIVE;
    }
    

    Then build a class that combines them together:

    public class Word
    {
        String word;
        SpeechPart part;
        EnumSet<SpeechModifier> modifiers;
    }
    

    Now you can model a whole word:

    Word w1 = new Word();
    w1.word = "bouncing";
    w1.part = SpeechPart.VERB;
    w1.modifiers = EnumSet<SpeechModifier>.of(SpeechModifier.PRESENT, SpeechModifier.PROGRESSIVE);
    

    This solution, however, doesn’t prevent non-sensical combinations, such as FIRST_PERSON NOUN PAST.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 472k
  • Answers 472k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm afraid that's not the correct usage of IExtensibleDataObject, the… May 16, 2026 at 3:36 am
  • Editorial Team
    Editorial Team added an answer Apple's answer is "it doesn't matter." Track your references properly… May 16, 2026 at 3:36 am
  • Editorial Team
    Editorial Team added an answer Check out the Managed Extensibility Framework (MEF). It can automatically… May 16, 2026 at 3:36 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.