How can I count the number of equal words between two strings?

Mario

How can I count the number of words that appear in two strings?

I'm thinking in something like this

      let $nequalwords := count($item[text() eq $speech])

What is the best way to do this?

I thought to go with a two fors comparing word by word, but I don't know if there are a better way to do this.

adamretter

How about splitting the strings on white space so that you end up with words, and then creating a sequence of the strings and removing those that are not distinct, i.e. those that appear in both strings, by then subtracting this from the count of all words you know how many words appeared in both strings. For example:

  let $distinct-words1 := distinct-values(tokenize($string1, "\s+"))
  let $distinct-words2 := distinct-values(tokenize($string2, "\s+"))
  let $all-words := ($distinct-words1, $distinct-words2)
  return
    count($all-words) - count(distinct-values($all-words))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I count number of commits between two branches?

How can I use lambda to count the number of words in a file?

How can I compare two strings and replace matching words with JavaScript?

How can I count the number of weekdays between two dates, considering Saturday a weekday?

How can I count the number of matching zero elements between two numpy arrays?

R: how can i make str_count look for the number of occurences of zero between two specific numbers?

Regex match two strings with given number of words in between strings

Python - count number of elements that are equal between two columns of two dataframes

How the Number of days can be calculated between two strings in PHP?

How can I measure the distance between two words in Java?

How can i add space between two words

How do I check if the number of occurrences of two words in a String is Equal without using loops?

How do I check if two strings are equal in Java when either one of the strings can be a null?

How do I count the number of words with the same length in a array of strings C

How can I check if a number is equal to a random number between 1 and the value of the number?

How can I count number of entries in two other tables with MYSQL?

How can I count the number of days between a 1 and the next 0

How can I extract the text between two strings in a log file?

How can I calculate Cosine similarity between two strings vectors

How can I tell the differences between two strings in Excel?

how can i find lcs length between two large strings

How can I find the first difference between two strings in Python?

How can i find specific charater in strings between two word?

How can I get sum of count between two dates in sqlite

How can I count the number of days that match between a data frame with two vectors (start date and end date) and a vector of dates?

How to count the same words found in two different strings using php?

How can I count the number of

How can I calculate the number of working days between two dates

How can I find the number of years between two dates?