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!
Related
I was making a discord bot and I want to make an account system, what my program supposed to do is to keep on finding a registered user by checking on the .json file over and over until it finds the two variable with the same value, problem is I can't find anything online for a solution. I just need a code for it :)
Sure! Try something like this:
with open('filenamehere', 'r') as f:
# Add Code to add values to a list called x here
After this, we can go ahead and do one of two things:
Run a simple if value is in list x, or
Run a for loop on the list until it reaches the value required.
Either way should give you the desired outcome. Sorry I was a little vague, your question was as well.
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 :)
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.
%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