• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Get to text descriptions and check similarities

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I would like to get two texts(for example the descriptions of two countries), and check if they belong to the same continent. Two texts from Africa will contain references to Lions so the code can determine that both countries are similar and that maybe they belong to the same continent

Is there any specific aproach or API for implement that?

And also for example if I want to list the events which are scheduled for today. Is there any free feed from which I could get the data?

Regards, Isaac
 
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like something for the grep tool.

Linux in a Nutshell by Ellen Siever, Stephen Figgins, Robert Love, and Arnold Robbins, page 182, wrote:grep
grep [options] pattern [files]
Search one or more files for lines that match a regular expression pattern. Regular expressions are described in Chapter 7. Exit status is 0 if any lines match, 1 if none match, and 2 for errors. See also egrep and fgrep

Of course, that probably won't work on a Windows® box.

Start by writing down an algorithm you intend to follow. Make it simple. Very simple.
 
Marshal
Posts: 4600
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Isaac Ferguson wrote:I would like to get two texts ...


Can you define what texts are?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
text one:


I mean descriptions then check both and get how similar they are, in order to know if both topics, for example desk computers and laptops
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example this code tell you if two texts are exactly equal



But I want to check the percentage of similarities. Any idea, please?
 
Campbell Ritchie
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't mess around with Exceptions.You cannot work out percentage similarities until you have an algorithm. What algorithm do you plan to use? Have you searched for such an algorithm?
 
Campbell Ritchie
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That loop will not work. I shall let you work out what will happen. After which you will (I hope) never go anywhere near a read() method again.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I try to run it, it shows compilation errors:




It says that abstract classes should be implemented, but I dont want that I just want it simple at the moment.

Any idea for change that code and make it works in the simplest way possible?
 
Campbell Ritchie
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use input streams for text files. Use file readers or Scanners.
But you will not manage to find similarities unless you have found an algorithm.

 Now is the time for all good men to come to the aid of the party.

Now is the time for all good men to come to the aid of the party.

Your technique will show 100% difference between those two pieces of text because one of them begins with a space.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying the next code:

The result shows that 2 words from the first text are contained in the second text. It makes a percentage of 66 % and it is rigth.The algorithm I made is too simple, I would like to find a more human understandable answer for example, in this case 2 of 3 words are equal but 66% sounds like they are plenty of differences when in reality they are nearly equal, of course if the texts would have 200 words each maybe it would make more sense.

Any idea of how to do it more "realistic"?
 
I am Arthur, King of the Britons. And this is a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic