how to handle strings in prolog - prolog

i need to check if a string is available in given prolog statement
example
related('also-5','be-8').
i want to check if be is there in this statement how to do?
please give me some link to detailed tutorial on string handling in prolog

Relevant sections in the SWI-Prolog manual:
Analysing and Constructing Atoms
Representing text in strings

Related

SWI-prolog semweb library processing of URI

Being new to prolog I am reading existing code (as well as trying to write some code). Having some prior background in semweb I started to play with it and see something that is confusing me. Example assertion:
?- rdf_assert(ex:bob, rdf:type, foaf:'Person').
I also did find the following in the documentation:
Remember: Internally, all resources are atoms. The transformations
above are realised at compile-time using rules for goal_expansion/2
provided by the rdf_db library
Am I correct in assuming that somehow the library is treating the three URIs as atoms? I thought that the compiler would treat this as module_name:predicate, but that does not seem to be the case. If that is true, could you please provide a simple example on how this could be done in prolog?
Thanks
Prolog is not a functional language. This implies 2+3 does not evaluate to 5 and is just a term that gets meaning from the predicate that processes it. Likewise, ex:bob is just a term that has no direct relations to modules or
predicates. Only predicates such call/1 will interpret this as "call bob in the module ex".
Next to that, (SWI-)Prolog (most Prolog's, but not all) have term expansion that allows you to rewrite the term that is read before it is handed to the compiler. That is used to rewrite the argument of rdf/3: each appearance of prefix:local is expanded to a full atom. You can check that by using listing/1 on predicates that call rdf/3 using the prefix notation.
See also rdf_meta

How can I make Prolog speak?

I have a list which holds some string values.
A = [John, goes, to, party].
How can I pass this text to speech?
Can any one tell me how to do text to speech conversion in prolog?
Check out the cowsay pack. pack_install(cowsay). Look at the 'add-ons' page on SWI-Prologs website.
You will need to use the foreign language interface of your Prolog system to call an external API that does the speech synthesis. Prolog foreign language interface are not standard but Prolog system specific. Thus, without further details, is not difficult to give you more specific advise.
UPDATE: An alternative solution to the use of the foreign language interface is for the Prolog process to write the strings to standard output and to use a shell pipe to pass those strings to the Python process that reads those strings from standard input.

what does" readin" predicate in prolog mean?

I have a question and I hope to help me:
what does" readin" predicate in prolog do?
I have searched in google but I have nothing
could you explain it to me with an example?
Regards.
I think you must be seeing readln not readin. The library predicate readln/1 reads tokens from an input line in the interactive SWI-Prolog console and makes a list of them. Most Prolog term reading predicates require a period to terminate input, but this predicate would include any terminating period in the list.
See here for a bit of documenation.

What is possible and not is with Prolog?

I'm new to Prolog and to logic paradigm development, but I think this can help me in my application. My first doubt is what can I do this with the language.
I'm doing some text processing/natural language processing and I think that my code will be clearer and easy doing it in a logical language than in Java (that is what I'm using and will integrate with Prolog).
My first goal now is discover the char type of a String (alphabetic, digit, numeric, etc...). I have four mais arguments: hasLetter, hasDigit, hasSymbol, hasPunctuation.
With Prolog, I can have one method determineType() that will return me the type based on this four attributes or it only with single tests, thinkgs like isDigit(), isAlphabetic(), etc?
The category or "type" of each character is a relation, relating a character to its type. You can code it in Prolog using a predicate. A meaningful name for such a predicate would for example be: "character_type(C, T)". In SWI-Prolog, check out the library predicates char_type/2 and code_type/2 to get this information. You can use them for obtaining the type(s) of a character (on backtracking, alternative solutions may be generated) as well as for testing whether a character belongs to a supplied category. For language processing, you may also find definite clause grammars (DCGs) useful.

How to do case conversion in Prolog?

I'm interfacing with WordNet, and some of the terms I'd like to classify (various proper names) are capitalised in the database, but the input I get may not be capitalised properly. My initial idea here is to write a predicate that produces the various capitalisations possible of an input, but I'm not sure how to go about it.
Does anyone have an idea how to go about this, or even better, a more efficient way to achieve what I would like to do?
It depends on what Prolog implementation you're using, but there may be library functions you can use.
e.g. from the SWI-Prolog reference manual:
4.22.1 Case conversion
There is nothing in the Prolog standard for converting case in textual data. The SWI-Prolog
predicates code_type/2 and char_type/2 can be used to test and convert individual
characters. We have started some additional support:
downcase_atom(+AnyCase, -LowerCase)
Converts the characters of AnyCase into lowercase as char_type/2 does (i.e. based on the
defined locale if Prolog provides locale support on the hosting platform) and unifies the
lowercase atom with LowerCase.
upcase_atom(+AnyCase, -UpperCase)
Converts, similar to downcase_atom/2, an atom to upper-case.
Since this just downcases whatever's passed to it, you can easily write a simple predicate to sanitise every input before doing any analysis.

Resources