ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Today I'm working on a database for a datalog program. I've gotten myself a bit stuck logically, I thought I had it figured out, but I've run into some dead ends.
I have Scheme inputs so basically a string with A Name and a list of list names. Then I have Facts, basically these lists have a name and a list of values.
I need to process the schemes create a lists with the name of the scheme which are lists with the variables and append the info from matching facts to the list of variables.
EG
Quote:
Scheme
listname A B C D
other A B
Fact
listname 1 2 3 4
listname 2 3 4 5
other 9 6
I would need to have generated the following lists
Quote:
A B C D
1 2 3 4
2 3 4 5
9 6
The issue I'm running into is that because I don't know how many lists I'll need until I see the input I'm using vector>>. The issue here is that when I encounter an element that only matches two of the lists, I don't quite know what to do. The issue is just getting more complex than I think it should be.
How can I generate separate lists that are easier to look at, and can vary in size?
So far I have made it so that I can take per the example above listname under schemes and facts and generate a nice vector, but then I get stuck when I hit other types such as other above.
I don't usually like to post such open questions on here, but I'm not super experienced in programming and am having trouble wrapping my head around a good way to get this done.
Thank you for any input!
Last edited by mitchell7man; 04-11-2014 at 07:34 PM.
I know very little about database design and nothing about datalog so this may not help .. but I think you need to work out which parts of the input you were given map to which database elements.
For example, a database table is a container for an array of objects of the same type, the columns in the table represent the attributes of the objects and the rows in the table represent an instance of an object...
Code:
person_physical_tbl:
id surname firstname sex dob height_cms hair_colour eye_colour
1 Smith John M 13/12/1911 190 Black Blue
2 Smith Jane F 10/09/1908 165 Blonde Brown
It may not make sense to put all the attributes of a complex object into one table so we can break it up into different tables and combine (join) the results when we need to
Code:
person_employment_tbl:
id surname firstname current_employer current_title previous_employer previous_title
1 Smith John null null Fairweather Friendly Society Financial Advisor
2 Smith Jane Scott Nofriends Social Media Content null null
It's a bit difficult to tell with your example but possibly your mapping may be:
Code:
Scheme
listname A B C D # listname->tablename1, A->column1, B->column2, C->column3, D->column4
other A B # other->tablename2, A->column1, B->column2
Fact
listname 1 2 3 4 # insert into tablename1 values(1, 2, 3, 4) # first instance of a tablename1 object
listname 2 3 4 5 # insert into tablename1 values(2, 3, 4, 5) # second instance of a tablename1 object
other 9 6 # insert into tablename2 values(9, 6) # first instance of a tablename2 object
I think most readers will be puzzled by your question; I know I am. I'll try to rephrase your question, to see if I understand it. Your terminology is unfamiliar to me, and I'm going to assume it comes from your particular problem domain.
A 'Scheme' is a general description of some sort of dataset? And a 'fact' is an instance of the aforementioned Scheme, holding real data?
If, by 'database', you are talking about a common relational database that uses tables composed of columns that define a particular format, then I would translate your description into two such tables. The first, named 'listname' would have four columns, named 'A', 'B', 'C', and 'D'. The second table named 'other', would have two columns named 'A' and 'B'. Possibly, the data for each row of the respective 'A' and/or 'B' columns constitutes a relation in the database, linking the two tables.
Is this sounding anything like what your describing?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.