Question

create computer program to translate real world descriptions into knowledge representations PS:pick whichever language you prefer:)....

create computer program to translate real world descriptions into knowledge representations

PS:pick whichever language you prefer:). And this is regarding artificial intelligence study.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

// TextProcess.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class TextProcess {

// method to load all words from a file into an array list

static ArrayList<String> fileToList(File file) {

// creating an array list

ArrayList<String> words = new ArrayList<String>();

// opening file

try {

Scanner scanner = new Scanner(file);

// loops and add each and every word to words list

while (scanner.hasNext()) {

words.add(scanner.next());

}

// closing file

scanner.close();

} catch (FileNotFoundException e) {

// error, the file is not in the same directory

System.out.println("File not found!");

}

return words;

}

// method to extract the words begin with a character ch from an array list

// of words

static ArrayList<String> beginsWith(ArrayList<String> inputList, char ch) {

// creating a list

ArrayList<String> result = new ArrayList<String>();

// looping through each word in input list

for (String word : inputList) {

// checking if word starts with the given character,

// note: this check is case sensitive, if you want to check without

// case sensitivity, convert word to lower case by calling

// word.toLowerCase() and convert ch to lower case by calling

// Character.toLowerCase(ch) just like below commented code

// if(word.toLowerCase().startsWith(""+Character.toLowerCase(ch))

if (word.startsWith("" + ch)) {

result.add(word);

}

}

return result;

}

// method to print all words in a list separated by space

static void print(ArrayList<String> inputList) {

for (String word : inputList) {

System.out.print(word + " ");

}

System.out.println();

}

public static void main(String[] args) {

//

/**

* creating file object. make sure that you have the file cs.txt in the

* root directory of your project. if not, copy the file from the

* folder, go to the IDE (eclipse, netbeans etc) right click on project

* name, click paste, the file will be added. If you fail to do this

* correctly, the file will not be loaded, and this is not mistake in my

* code.

*/

File file = new File("cs.txt");

//loading words

ArrayList<String> words = fileToList(file);

//getting words start with 'a'

ArrayList<String> wordsBeginWithA = beginsWith(words, 'a');

//printing words start with 'a'

print(wordsBeginWithA);

}

}

/*OUTPUT*/

and approach and applications. and algorithms acquisition, and access as a and a and a and as and are abstract, as applications. approaches aspects and and and accessible

Kindly Upvote if Helpful :)
HOPE THIS MAY HELP YOU----------------------

------------------------------THANK YOU---------------------------

Add a comment
Know the answer?
Add Answer to:
create computer program to translate real world descriptions into knowledge representations PS:pick whichever language you prefer:)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT