I want to query the "instance of P31" and "health specialty P115" for a disease name
"left bundle branch hemiblock (Q2143688)"
I want an output like :
left bundle branch hemiblock (Q2143688)
instance of : thoracic disease
health specialty :cardiology
Also is it possible to query all disease information with its instance of and health specialty, so that I can store it and process each time I need an information.
Related
Example:
Students want to enroll in multiple courses of different course groups (Math, English, Spanish, History) and have issued preferences for each course group (ENG-1 > ENG-2 means course ENG-1 is preferred to course ENG-2).
Student A:
MATH-2 > MATH-4 > MATH-1 > ... > MATH-9
ENG-3 > ENG-4 > ENG-1 > ... > ENG-2
Student B:
ENG-1 > ENG-2 > ENG-4 > ... > ENG-3
SPA-4 > SPA-6 > SPA-3 > ... > SPA-2
HIST-1 > HIST-3 > HIST-2 ... > HIST-5
Student C:
...
Is it possible for a planning variable of each student (planning entity) to be a combination of each of their preferences? I.e. student A would be assigned MATH-2 and ENG-3, student B would be assigned ENG-1, SPA-4, and HIST-1, if the constraints allow for this.
Yes (and no). Technically no, because #PlanningVariable can only hold a single value.
But YES, OptaPlanner can handle your use case. You just need to choose the right way to map your domain to Java classes. You need to model a N:M relation between Student and Course:
Student A needs to enroll in 2 courses (one from the MATH group and one from the ENG group).
Student B needs to enroll in 3 courses (ENG, SPA, HIST).
etc.
You can model this type of relationship with the CourseAssignment class, which is your #PlanningEntity. It could look like this:
#PlanningEntity
class CourseAssignment {
final Student student; // e.g. Ann
final CourseGroup courseGroup; // e.g. MATH
#PlanningVariable(valueRangeProviderRefs = { "courseRange" })
Course course; // changed by Solver - could be MATH-1, MATH-2, ENG-1, HIST-...
}
Since the number of course assignments is known for each student and it's fixed, you'd simply create 2 CourseAssignment instances for Student A, 3 instances for Student B, etc.
Next, design your constraints to penalize each courseAssignment with a hard score penalty, if courseAssignment.course.group != courseAssignment.courseGroup and with a soft score penalty based on courseAssignment.student.getPreference(courseAssignment.course).
I'm very well aware of basic SQL queries, however I've never worked with a query that deals with hierarchical data.
I'm using the Telerik TreeView control to display data related to a school board with the following structure:
--School "ABC"
----Class "Grade 1"
----Class "Grade 2"
------Student #1
------Student #2
--School "DEF"
----Class "Grade 1"
------Student #3
----Class "Grade 3"
The TreeView is in a tri-state checkbox mode, so each element can be checked off. So if a single child element is checked then the parent element will be checked as well, and when checking a parent element all the child elements will be checked.
After checking off some schools, classes, and students, the following screen displays information about the students in a graph which currently uses the school IDs (if multiple are checked) to select all students of those schools.
Here's where it gets tricky. Using the above structure as an example, I select the class "Grade 1" from the school "ABC" and class "Grade 3" from the school "DEF" which in turn will select the students #1 & #2 AND the schools "ABC" & "DEF".
Selected schools: ABC, DEF
Selected classes: Grade 1, Grade 3
Selected Students: #1, #2
As mentioned before, my current SQL query is based solely on the school ID and I know that I can't simply add two other conditions in the where clause that look like this:
AND ClassID IN ('Grade 1', 'Grade 3') --Note there is no primary key for classes, and I can't change that in my position..
AND StudentID IN (1,2)
as this will also select student #3 from the other class title "Grade 1"
So my question is, how to I combine the School ID(s), Class name(s), and student ID(s) into one condition that will solve this issue.
Edit:
Here's a structure of the tables.
If i understand you correctly you have the selected school, class and student. So would this work for you:
where (school = "ABC" and
class = "Grade1")
OR
(school = "DEF" and
class = "Grade3")
I hope i understood your requirements correctly.
I need to make an one-to-one relationship between two tables, it means, each passenger can only reserve one seat on a flight.
I have 4 tables:
Passenger : passengerId(PK), passengerName, PassengerAddress
Seat : seatId(PK), seatClass, flightId(Fk)
Flight : flightId(PK), flightDate
Reseveration : flight(PK), seatId(PK), passengerID(FK), reserveDate
Passenger : passengerId(PK),passengerName,PassengerAddress
//in this table make passneger id primary key as passenger will be unique with his details
Seat : seatId(PK),seatClass,flightId(Fk)
//in this table add a field say passenger id so that a passenger who is allotted in a flight will be mained here eg pasneger x in flight y.,also you can maintain a time for fligh such that if a passneger wantes to travel two times a day in a same flight
Fligth : flight Id(PK),flight Date
//make flight id unique hare
Reseveration: flight(PK),seatId(PK),passenger ID(FK),reserveDate
//this will be the final table reservation where you have all the details with no duplicacy.
Sorry for the vague question topic!
I've got a particular relational-algebra problem that has me and a couple of friends stumped.
Now, here's the question:
For each department, find the maximum salary of instructors in that
department. You may assume that every department has at least one
instructor.
I'll upload the schema as well, as a visual aide.
I've worked this out to a point;
I need a relation that includes all the instructors in any department, we've got that. It's the instructor relation.
Out of that relation i need to 'split' it up into a per-department basis. and once I have that relation I just take the max(salary) and return that.
Problem is, the only way I can think of to do that is something like this:
π(max(salary)(σ(dept_name = x(instructor)))
Where x = whatever dept_name i'm looking for, but If I did it this way, then I'd have to do a new relation for every department!
How would you do it?
(Note: I just copy and paste'd the symbols from wikipedia if you want to use them in your answer)
My relational algebra might be a bit rusty but I think that
dept_name_G_{max(salary)}(
σ_{ddept_name = idept_name}(
ρ_{dept_name/ddept_name}(department) ⨯
ρ_{dept_name/idept_name}(instructor)
)
)
is what you seek for.
Remember that all projections are just operations on sets. The first thing you would do to
connect the information of department and instructor is to bring the information together.
So you want to join department and instructor, basically a cross product (⨯):
department = {(depA, 100$), (depB, 200$)}
instructor = {(will, depA, 10$), (bob, depB, 20$), (will, depB, 9$)}
department ⨯ instructor = {
(depA, 100$, will, depA, 10$),
(depA, 100$, bob, depB, 20$),
...,
(depB, 200$, will, depA, 10$),
...
}
So what you would want now is to filter the tuples where the dept_name of the instructor equals the
dept_name of the department. But you also notice that you now have a naming collision,
namely the column dept_name comes up twice.
As you can't simply do σ_{dept_name = dept_name}(department ⨯ instructor) you need to rename at
least one of the dept_name fields. I renamed both for clarity which one belongs to what.
So what you now have is
σ_{ddept_name = idept_name}(
ρ_{dept_name/ddept_name}(department) ⨯
ρ_{dept_name/idept_name}(instructor)
)
giving you:
{
(depA, 100$, will, depA, 10$),
(depB, 200$, bob, depB, 20$),
(depB, 200$, will, depB, 9$)
}
The whole process is a natural join and can be expressed shortly with:
department ⋈ instructor
Now the final step is to project the maximum salary per department. A simple projection can't do that
but the aggregation operator can:
{dept_name}_G_{max(salary)}(department ⋈ instructor)
results in
{
(depA, 10$),
(depB, 20$)
}
Hi could someone please verify my work. Im not sure if im doing any of this correctly and would greatly appreciate any help. I am not allow to use the Bow tie operator. Thank you.
Question:
Books (ISBN, Title, Authors, Publisher, Ed, Year, Genre)
Patron (MemberNumber, FirstName, LastName, AddressLn1, AddressLn2, City, State, Zipcode)
Loan (MemberNumber,ISBN,DateLoaned,DateDue, DateReturned)
Business Logic
• You may assume that the library only has one copy of each book.
• Each book may have many authors. If a particular book has multiple authors, they are listed as a comma separated string. You may assume that the same author always uses the same exact name and no two authors will have the same name.
• Year is stored as an integer.
• DateLoaned, DateDue, and DateReturned are stored as a date.
• When a book is initially lent out, DateReturned is set to be NULL, upon its return, the value is updated.
1.1. Find all books that were loaned out after 12/22/2012. Show the ISBN, Title, and DateDue.
1.2. Find all library patrons who have borrowed a book titled "Database Systems". Show their FirstName, LastName, and DateLoaned.
1.3. Find all books that were ever loaned out. Display the ISBN.
1.4. Find all books returned before 12/22/2012. Display the ISBN.
1.5. Find all books returned on or after 12/22/2012. Display the ISBN.
1.6. Find all books returned either (before 12/22/2012) or (on or after 12/22/2012) Display the ISBN.
1.7. In 1 sentence explain the difference between 1.3 and 1.6.
1.8. Find all patrons who have never borrowed a book.
1.9. Find all books with Genre "Mystery" that have NEVER been loaned out.
1.10. Create a new attribute ImportantDates. A date is important if it is in the Loan relation either as a DateLoaned or a DateDue. Display ImportantDates.
1.11. Find all library patrons who have borrowed a book with an author "James Stewart". You may use the expression LIKE "%James Stewart%" in your Relational Algebra.
1.12. Find all library patrons who have never borrowed a book with an author "James Stewart". You may use the expression LIKE "%James Stewart%" in your Relational Algebra.
1.13. Find all library patrons who have only borrowed a book with an author "James Stewart". If they have ever borrowed a book without the author "James Stewart" they should be excluded. You may use the expression LIKE "%James Stewart%" in your Relational Algebra.
Answer:
1.1) πISBN,TITLE,DATEDUE(σDATELOANED > 12222012 AND BOOKS.ISBN = LOAN.ISBN(LOAN X BOOKS)
1.2) πFIRSTNAME,LASTNAME,DATELOANED(σTITLE = "DATABASE SYSTEMS" AND BOOKS.ISBN = LOAN.ISBN AND PATRON.MEMBERNUMBER = LOAN.MEMBERNUMBER(BOOKS X PATRON X LOAN))
1.3) πISBN(σDATELOANED <> "NULL" AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS))
1.4) πISBN(σDATELOANED < 12222012 AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS))
1.5) πISBN(σDATELOANED >= 12222012 AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS))
1.6) πISBN(σDATELOANED >= 12222012 OR DATELOANED <12222012 AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS))
1.7) 1.3 AND 1.6 are the same as they both find books that have been loaned.
1.8) σDATELOANED = "NULL" AND PATRON.MEMBERNUMBER = LOAN.MEMBERNUMBER(LOAN X PATRON)
1.9) σGENRE = "MYSTERY" AND BOOKS.ISBN = LOAN.ISBN AND DATELOANED = "NULL"
1.10) LOAN(DATELOANED,DATEDUE) -> IMPORTANTDATE
Could you please give me an example of either 1.11, 1.12, or 1.13 as I have no clue in how to use the LIKE expression.
The professor told you how to do it:
You may use the expression LIKE "%James Stewart%" in your Relational Algebra.
It has been about a year since I have had to use relational algebra, but it will be whatever your pre-conditions are (this is a task for you) followed by the line:
LIKE %James Stewart%
The SQL statement would look something like this:
Select * from patrons p where Books.author LIKE %James Stewart%
You will find in your studies relational algebra does not deal with functions of SQL it just looks at the purely mathematical side of things.