1

I'm working for a school project. Purpose of the program looking for the "Same" and "similar" words via input. I don't know how to find similar words numbers or just words.

FOR EXAMPLE:

INPUT: Car

OUTPUT: FOUND: CAR SIMILAR WORDS: 3(or the Words like 'carhood').

 boolean cnt = false;
 while(!cnt){
 // Variables
 ArrayList<String> WordList = 
 new ArrayList<>(Arrays.asList("açık",...."zorunda"));
 String Word = "";
 int WordIndex = 0;
 int WordListSize = WordList.size();
 boolean result = false;
 System.out.print("Kelime Giriniz: ");
 String Input = new Scanner(System.in).nextLine();
 // Search Loop
 for (int i = 0; i < WordListSize; i++) {
 // Temporary variables
 Word = WordList.get(i);
 WordIndex = WordList.indexOf(Word);
 // If there is word in word list
 if(Word.equalsIgnoreCase(Input)) {
 System.out.println("Kelime bulundu.");
 System.out.println("Kelime : "+Word);
 System.out.println("Kayıt Numarası : "+WordIndex);
 // Comparison number
 System.out.println(WordIndex+" Kelime ile karşılaştırıldı.");
 result = true;
 break;
 }
 }
 if(!result) {
 System.out.print("Kelime tarandı:");
 System.out.println((WordList.size()));
 System.out.println("Kelime bulunamadı.");
 }
 System.out.println("--");
 System.out.println("Devam etmek ister misiniz ?");
 System.out.println("'1' Evet, '0' Hayır.");
 System.out.println("--");
 int answer = new Scanner(System.in).nextInt();
 if(answer ==0){
 System.out.println("Çıkış yapaılıyor..");
 cnt= true;
 }
 }

it is Turkish btw.

Nicholas K
15.4k8 gold badges35 silver badges59 bronze badges
asked Dec 12, 2018 at 14:12
5
  • 2
    What is the question/problem? Commented Dec 12, 2018 at 14:13
  • i don't know how to find similliar words Commented Dec 12, 2018 at 14:15
  • "Similar" is not very precise. You need to figure out what it means to be "similar". Is it enough to use String.startsWith()? Or String.contains()? Those might be good places to start at least. Commented Dec 12, 2018 at 14:17
  • try contains() method on String then. Commented Dec 12, 2018 at 14:21
  • 1
    i want to find words like. "Input: Car", Shows "Car" and "Carhood","Carlight" etc. words that contains input word. Commented Dec 12, 2018 at 14:22

2 Answers 2

3

You can do so easily using java-8 :

// Assuming this is your list
List<String> myList = Arrays.asList("Carhood", "Carlight", "Tree", "Red", "Carrom");
// using a filter and then collecting 'similar words' to a list
List<String> collect = myList.stream()
 .filter(s -> s.contains("Car"))
 .collect(Collectors.toList());
// to print it out
collect.forEach(System.out::println);
answered Dec 12, 2018 at 14:26

Comments

1

Actually there are lots of algorithms to check string similarity. You can read about lots of them and chose the favorite one using this link: https://github.com/tdebatty/java-string-similarity

There also is a maven dependency:

<dependency>
 <groupId>info.debatty</groupId>
 <artifactId>java-string-similarity</artifactId>
 <version>RELEASE</version>
</dependency>

and a couple of usage examples there.

In short you should set some kind of similarity coefficient and based on that algorithm will decide if strings are similar enough or not based on metrics like https://en.wikipedia.org/wiki/Levenshtein_distance

answered Dec 12, 2018 at 14:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.