Please edit the program to where it does what I asked for. I need an original answer that edits my code to do the following of what I asked for above here is my Java code  import java.util.*; import java.util.stream.Collectors; public class CFG {     private static Map> rules;     public static void main(String[] args) {         rules = new HashMap<>();         initializeGrammarRules();         String sentence = generateSentence("S");         System.out.println(sentence);     }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help with my context free language. It needs to do the following 1. Developing a language model based on the context-free grammar: Use the context-free grammar to develop a language model that can be used to generate coherent and grammatically correct sentences in American English.
2. Incorporating semantic information into the context-free grammar: Expand the context- free grammar to incorporate semantic information, such as word meaning and context, to generate more meaningful sentences in American English. 

Please edit the program to where it does what I asked for. I need an original answer that edits my code to do the following of what I asked for above

here is my Java code 

import java.util.*;
import java.util.stream.Collectors;

public class CFG {
    private static Map<String, List<String>> rules;

    public static void main(String[] args) {
        rules = new HashMap<>();
        initializeGrammarRules();

        String sentence = generateSentence("S");
        System.out.println(sentence);
    }

    private static void initializeGrammarRules() {
        rules.put("S", Arrays.asList("NP VP"));
        rules.put("NP", Arrays.asList("Det N", "Det AP N"));
        rules.put("AP", Arrays.asList("Adj", "Adj AP"));
        rules.put("VP", Arrays.asList("V NP", "V NP PP"));
        rules.put("PP", Arrays.asList("P NP"));
        rules.put("Det", Arrays.asList("the", "a", "an"));
        rules.put("N", Arrays.asList("cat", "dog", "book", "tree"));
        rules.put("Adj", Arrays.asList("big", "small", "brown", "green"));
        rules.put("V", Arrays.asList("chased", "ate", "read", "climbed"));
        rules.put("P", Arrays.asList("in", "on", "under", "above"));
    }

    private static String generateSentence(String symbol) {
        List<String> alternatives = rules.get(symbol);

        if (alternatives == null) {
            return symbol;
        }

        String expansion = alternatives.get(new Random().nextInt(alternatives.size()));
        String[] symbols = expansion.split("\\s+");

        return Arrays.stream(symbols)
                .map(CFG::generateSentence)
                .collect(Collectors.joining(" "));
    }
}

edit the program to achieve the results I've stated before.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education