prolog - Count the occurence of a string in a string -


So I want to give a list of keywords, and whenever a word comes in a string, to increase. That's why I'm playing for a while but I can not work on it. This is what I have done whenever I run a question: I get an error like this: Error: Score / 3: Arguments are not adequately started .

  score ([], 0, document title, _)). Score ([H.Te], ACC, document (title, _): - sub-string (case_inensive, h, title), ac 1ac + 1, score (t, ac 1, document (title, _) is.  

My questions are written like this: ? - document (t, _), score ([rule], ac, document (t, _)

When you enter the score ([rule], acc, document (t, _) Asks , variable ACC is deprecated (no value) so that your ACC1 AC + 1 fails because 1 < There is nothing to add to / code> ( arguments have not been adequately immediately ). In addition, your cacher continues to grow in recursion, but the case of your base is triggered when the accumulator goes to zero ( or ), then the case of your recurring basis assumes that the accumulator is less than zero Has been doing).

It seems that you have seen the use of depositors before, but how are you mixing two different methods, how it is used (counting or counting), and you have the initial bill Not that which starts the accumulator, so you are trying to do this with the initial query.

Here is an annotated working version. You have to start with the initial accumulator of zero, which will then be counted.

  score (tag, calculation, document): - score (tag, 0, calculation, document). Start the container at% zero% and there are no more tags, so the present container is that our resultant count is% and we do not take into account that the document argument on this point score ([], A, A, _) is. Score (tag [tag | tag], acc, calculation, document (title, _): - sub-string (case_incentive, tag, title), check for tag in% title Acc1 Acc + 1,% increase ACC Found score (tag, acc 1, calculation, document (title, _)). The remaining points score is  

but there is another problem: if sub_string / 3 never fails (a single tag is not found) Then score / 4 will be completely unsuccessful, so there is a need to be repeated recursive, if the tag is not found, but without increasing the cumulative. The easiest way to do this is to repeat the score / 4 prediction:

  using the prologue created in the score  if-then-second  Tag (title | tags), acc, math, document (title, _): - (sub_string (case_interest, tag, title)% check for tag in title -> AC 1 AC + 1% increase ACC Get; AC1 = Acc% otherwise, no increments), score (tag, acc 1, calculation, document (title, _)). Score of the remaining digit  

above, your query, ? - Use the document (T, _), score ([rule], acc, document (t, _). should work because there is only one tag, the result is either acc = 0 or Acc = 1 .


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -