For a school project I am attempting to write what is described as an "interactive diagnosis environment" using prolog. The user will enter a symptom, and a list of diseases that match the symptom will be printed to the screen. The user will then list another symptom, and diseases will be removed from the previous list if they do not match the second symptom, forming a new list. The new list is then printed.
example user input:
SYMPTOM_IN(fever, 150).
SYMPTOM_IN(vomiting, 1).
A list of possible diseases is printed after each input.
This process is repeated until a diagnosis is made or until it is somehow determined that it can't, at which point tests will be suggested and the user can input data regarding the tests in a similar manner, ultimately arriving at a diagnosis.
So far, all I have is a list of facts that will compile and that I can then interact with, but I really don't understand how I am supposed to carry over the list of diseases from one input to the next. I also don't understand how to move from taking symptom input to suggesting tests, although maybe that will be evident once I understand how to do the symptom input portion.
I would really appreciate any help.
Thanks.
EDIT:
Could I take the two values from the SYMPTOM_IN call, use them to do something like symptom(X, fever, 150)., and assert the output from that to store it (like in the answer to this question)? Then maybe I can do the same thing for the next call and take the union of the two lists?
You want to create an expert system. There is a lot of info about it on the net. For example:
https://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_17.html
http://www.amzi.com/ExpertSystemsInProlog/02usingprolog.php
There is also a lot of good info on Stack Overflow.
In short: you need to know how to use assert and retract in proper way.
Related
Struggling to find rank values from highest to lowest, please see attached example of what I'm trying to achieve.
My current custom expression is:
Sum([ViolationAmt])
I have tried this:
Sum([ViolationAmt]) over Rank([ViolationAmt])
I've played around with the rank expressions however unable to implement...would be very grateful for some help.
Spotfire Rank Example
I need to make a lot of assumptions here because I don't know anything about your data set or really what your end goal is, so please comment back and/or provide more info in your question if I am off base.
the first assumption is that each row in your dataset represents one, for simplicity, [AccountID] with a [ViolationAmt]. I'm also guessing you want to show the top N accounts with the highest violations in a table, since that's what you've shown here.
so it sounds like you are going to need two calculated columns: one for getting the total [ViolationAmt] per account, and then another to rank them.
for the first, create a column called [TotalViolationAmt] or somesuch and use:
Sum([ViolationAmt]) OVER ([AccountID])
for the second:
Rank([TotalViolationAmt])
it will be useful to read the documentation on ranking functions if you haven't already.
you could probably combine these two into a single column with something like:
Rank(Sum([ViolationAmt]) OVER ([AccountID]))
but I haven't tested this at all. again, if you put in a bit more detail about what you're trying to accomplish it will help you get a better, more detailed answer :)
Quick rundown, basically, the idea of the prolog program (GNU Prolog) is to search a database containing people with available time slots to a set of times (beginning time, end time) and return the first person who can meet in that time. The input has the syntax
meeting(Person,slot(time(10,0),time(12,30)))
I have a predicate which matches the above as such:
meeting(Person, slot(time(A,B),time(C,D))) :- %insert code
and the database entries look as such:
free(george,slot(time(9,30),time(11,0)))
Where I am stuck is that I'm not sure how I can compare the times in the database with the times entered when calling my meeting predicate. Not looking for a free answer, just wanting a push in the right direction and a good example :) Thanks everyone!
Doing what mbratch said, I saw better how prolog runs through the database and I was able to easily write come comparing logic which would satisfy the requirements.
The idea is, calling free(...) as above, Person receives the first individual in the list and all the passed variables receive the data. Then I could use my logic on the data and if all the logic passes, the method runs through and the proper response is returned.
Thanks for your help!
%Examples
%course_meetings(maths4,tutorial,t07,khaled_mohamed,'tutorial for t07')
%days([sat,sun...])
%tutorialrooms([c6301,b4108,c2201,c2301,c2202,c2203])
%slots([1,2,3,4,5])
day_tut(Day,Slot,Place,Course,Group,Instr,Descr):-
days(X),member(Day,X),
tutorialrooms(X1),member(Place,X1),
course_meetings(Course,tutorial,Group,Instr,Descr),
slots(X2),member(Slot,X2).
I thought of using Assert but I am new to prolog not sure how it works the idea is that eventually I would like to create a schedule for all groups according to certain rules example each group should have a day off and lectures should preceed tutorials ...
My suggestions are coming from SWI-Prolog.
You can insert data to a dynamic database using assert/1; you can put the tuple on the Linda table with out/1 or use even more advanced features such as db_assert.
The question is, however, not HOW to record this data but rather WHY do you want to do it. Depending on how do you intend to address the scheduling problem you might need this recording strategy or that, or may be even none.
I saw an intern opportunity in a bank in dubai. They have a defined problem statement to be solved in 2 months. They told us just 2 lines -
"Basically the problem is about name matching logic.
There are two fields (variables) – both are employer names, and it’s a free text field. So we need to write a program to match these two variables."
Can anyone help me in understanding it? Is it just a simple pattern matching stuff?
Any help/comments would be appreciated.
I think this is what they are asking for:
They have two sources of related data, for example, one from an internal database, and the other from name card input.
Because the two fields are free text fields, there will be inconsistency. For example, Nitin Garg, or Garg, Nitin, or Mr. Nitin Garg, etc. Here is an extreme case of Gadaffi.
What you are supposed to do is to find a way to match all the names for a specific person together.
In short, match two pieces of data together by employer names, taking possible inconsistency into account.
Once upon a time there was a nice simple answer to the problem of matching up names despite mis-spellings and different transliterations - Soundex. But people have put a lot of work into this problem, so now you should probably use the results of that work, which is built into databases and add-ons - some free. See Fuzzy matching using T-SQL and http://anastasiosyal.com/archive/2009/01/11/18.aspx and http://msdn.microsoft.com/en-us/magazine/cc163731.aspx
Um so I was in for a little bit of a surprise tonight. I spent a good 20 mins trying to figure out why I was able to submit a form knowing that what I entered into the recaptcha field was invalid. Is it true that you don't need to input the exact words it displays? If it shows me two words and I misspelled one of the words, I still pass validation? Same goes if "hello world" and I input "hell man" it still works.
With recaptcha, you are only tested on one of the words, while the other is used to help computers in scanning printed material. So you only need to get one right to pass (which one you need is random). :D
the recaptcha site describes why this is. You need to get one of the two words correct; only recaptcha knows which one.
But if a computer can't read such a
CAPTCHA, how does the system know the
correct answer to the puzzle? Here's
how: Each new word that cannot be read
correctly by OCR is given to a user in
conjunction with another word for
which the answer is already known. The
user is then asked to read both words.
If they solve the one for which the
answer is known, the system assumes
their answer is correct for the new
one. The system then gives the new
image to a number of other people to
determine, with higher confidence,
whether the original answer was
correct.