LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2014, 08:32 PM   #1
mitchell7man
Member
 
Registered: Jan 2007
Location: Draper, UT
Distribution: Ubuntu, Windows 10, OSX
Posts: 461

Rep: Reputation: 31
Smile Need help creating database for datalog program!


Thank you for all the help so far!

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 08:34 PM.
 
Old 04-13-2014, 07:16 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 652Reputation: 652Reputation: 652Reputation: 652Reputation: 652Reputation: 652
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
Good luck!
 
Old 04-18-2014, 08:34 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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?
 
  


Reply

Tags
c++, concept, construction, database


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating LLDAP database? jnojr Linux - Server 7 08-05-2009 08:04 PM
About creating database satimis Linux - Server 2 06-14-2007 02:12 PM
sms program and database in linux web program in windows.. does not see each other.. keikun_naruchan Programming 0 07-06-2005 02:40 AM
creating database using awk RajaRC Linux - General 11 07-30-2004 06:33 AM
Creating an RPM database Null Linux - Software 6 03-20-2003 07:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration