trying to put it all together

Reply

Join Date: Apr 2009
Posts: 13
Reputation: externalaw is an unknown quantity at this point 
Solved Threads: 0
externalaw externalaw is offline Offline
Newbie Poster

trying to put it all together

 
0
  #1
Apr 5th, 2009
Hi,

I am Mike and run a small law student site,
recently I was donated a dictionary and have a glossary system installed on my forum.

I am pretty bad with scripting but hope someone can help me along,

What I want is to put the dictionary written like this,

A MENSA ET THORO, from bed and board. A divorce a mensa et thoro, is rather a separation of the parties by act of law, than a dissolution of the marriage. It may be granted for the causes of extreme cruelty or desertion of the wife by the hushand. 2 Eccl. Rep. 208.

This kind of divorce does not affect the legitimacy of children, nor authorize a second marriage. V. A vinculo matrimonii; Cruelty Divorce.

A PRENDRE, French, to take, to seize, in contracts, as profits a prendre. Ham. N. P. 184; or a right to take something out of the soil. 5 Ad. & Ell. 764; 1 N. & P. 172 it differs from a right of way,

which is simply an easement or interest which confers no interest in the land. 5 B. & C. 221.

A QUO, A Latin phrases which signifies from which; example, in the computation of time, the day a quo is not to be counted, but the day ad quem is always included. 13 Toull. n. 52 ; 2 Duv. n. 22. A court a quo, the court from which an appeal has been taken; a judge a quo is a judge of a court below. 6 Mart. Lo. R. 520; 1 Har. Cond. L. R. 501. See Ad quem.

A RENDRE, French, to render, to yield, contracts. Profits a rendre; under this term are comprehended rents and services. Ham N. P. 192.

A VINCULO MATRIMONII, from the bond of marriage. A marriage may be dissolved a vinculo, in many states, as in Pennsylvania, on the ground of canonical disabilities before marriage, as that one of the parties was legally married to a person who was then living; impotence, (q. v.,) and the like adultery cruelty and malicious desertion for two years or more. In New York a sentence of imprisonment for life is also a ground for a divorce a vinculo. When the marriage is dissolved a vinculo, the parties may marry again but when the cause is adultery, the guilty party cannot marry his or her paramour.

AB INITIO, from the beginning.
several thousand long,

I want to script this so that the word (in capitols) is placed into one column and the definition in an another column,

I can then place this in to my database, by import..

Can someone help me out?
Last edited by externalaw; Apr 5th, 2009 at 9:10 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: trying to put it all together

 
0
  #2
Apr 5th, 2009
I'm not sure what you mean by in a column... in a text file?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: externalaw is an unknown quantity at this point 
Solved Threads: 0
externalaw externalaw is offline Offline
Newbie Poster

Re: trying to put it all together

 
0
  #3
Apr 5th, 2009
Originally Posted by Comatose View Post
I'm not sure what you mean by in a column... in a text file?
Sorry yes, in a text file.
Then I can export my database to excel and cut and paste the two columns into there, and import it back into phpmyadmin, a total noob way of doing things I am sure!


Mike
Last edited by externalaw; Apr 5th, 2009 at 9:22 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: trying to put it all together

 
0
  #4
Apr 5th, 2009
Ah, ok... so in the new text file, you want it Tab delimited... so the upper case words <tab> definition. K.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: externalaw is an unknown quantity at this point 
Solved Threads: 0
externalaw externalaw is offline Offline
Newbie Poster

Re: trying to put it all together

 
0
  #5
Apr 5th, 2009
Originally Posted by Comatose View Post
Ah, ok... so in the new text file, you want it Tab delimited... so the upper case words <tab> definition. K.
Yeah I guess so, I will then just cut and pase it into excel in 2 columns,

M
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: trying to put it all together

 
0
  #6
Apr 6th, 2009
Originally Posted by externalaw View Post
Sorry yes, in a text file.
Then I can export my database to excel and cut and paste the two columns into there, and import it back into phpmyadmin, a total noob way of doing things I am sure!


Mike
I think it would be easier to write the shell script to generate SQL output directly so you can 'source' that SQL file right into your database via phpmysqladmin.

Are all of the CAPITALS terminated with a comma? If so, the task is easier. If many or most are, manually edit the text file to make it 'conformant'.

Give me a little time; I'll work up something using awk() and sed().

N
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: externalaw is an unknown quantity at this point 
Solved Threads: 0
externalaw externalaw is offline Offline
Newbie Poster

Re: trying to put it all together

 
0
  #7
Apr 6th, 2009
Hi,

I send you a PM with the source and database structure..
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: trying to put it all together

 
0
  #8
Apr 6th, 2009
Try the following two files, an awk script and a sh script. Put them both in the same working directory.
  1. Put your text into lawdict.txt and ensure it conforms to the one requirement: that all of the ALL CAPS TITLES end with a comma (,).
  2. Execute the command sh lawdict.sh.
  3. Edit lawdict.sql and change the last trailing comma to a semi-colon (;).
You now have an example of a shell-script-generated SQL command file.

It ain't perfect, and someone with a fresher brain will probably simplify this and make it about perfect. But the result (the example at the very end) is close to what you need.

lawdict.awk:
Shell Scripting Syntax (Toggle Plain Text)
  1. BEGIN { lineout = ""; printf("INSERT INTO law_dict_table VALUES\n");}
  2. {
  3. if ($0 ~ /^[A-Z ]*,/) {
  4. if (substr(lineout, length(lineout)-6) == "</p><p>") {
  5. lineout = substr(lineout, 1, length(lineout)-7);
  6. }
  7. printf("('%s'),\n", lineout);
  8. lineout = $0;
  9. } else {
  10. if ($0 ~ /^$/) {
  11. lineout = lineout "</p><p>";
  12. } else {
  13. lineout = lineout $0;
  14. }
  15. }
  16. }
  17. END {
  18. printf("VALUES ('%s'),\n", lineout);
  19. }

lawdict.sh:
Shell Scripting Syntax (Toggle Plain Text)
  1. #! /bin/sh
  2.  
  3. (
  4. sed -e "s/'/\'/g" -e 's/\\/\\\\/g' lawdict.txt \
  5. | awk -f lawdict.awk \
  6. | sed -e 's= </p>=</p>=g' -e "s/^\(('[A-Z ]*\),/\1','/"
  7. ) > lawdict.sql

Example lawdict.sql:
Shell Scripting Syntax (Toggle Plain Text)
  1. INSERT INTO law_dict_table VALUES
  2. (''),
  3. ('A MENSA ET THORO',' from bed and board. A divorce a mensa et thoro, is rather a separation of the parties by act of law, than a dissolution of the marriage. It may be granted for the causes of extreme cruelty or desertion of the wife by the hushand. 2 Eccl. Rep. 208.</p><p>This kind of divorce does not affect the legitimacy of children, nor authorize a second marriage. V. A vinculo matrimonii; Cruelty Divorce.'),
  4. ('A PRENDRE',' French, to take, to seize, in contracts, as profits a prendre. Ham. N. P. 184; or a right to take something out of the soil. 5 Ad. & Ell. 764; 1 N. & P. 172 it differs from a right of way,</p><p>which is simply an easement or interest which confers no interest in the land. 5 B. & C. 221.'),
  5. ('A QUO',' A Latin phrases which signifies from which; example, in the computation of time, the day a quo is not to be counted, but the day ad quem is always included. 13 Toull. n. 52 ; 2 Duv. n. 22. A court a quo, the court from which an appeal has been taken; a judge a quo is a judge of a court below. 6 Mart. Lo. R. 520; 1 Har. Cond. L. R. 501. See Ad quem.'),
  6. ('A RENDRE',' French, to render, to yield, contracts. Profits a rendre; under this term are comprehended rents and services. Ham N. P. 192.'),
  7. ('A VINCULO MATRIMONII',' from the bond of marriage. A marriage may be dissolved a vinculo, in many states, as in Pennsylvania, on the ground of canonical disabilities before marriage, as that one of the parties was legally married to a person who was then living; impotence, (q. v.,) and the like adultery cruelty and malicious desertion for two years or more. In New York a sentence of imprisonment for life is also a ground for a divorce a vinculo. When the marriage is dissolved a vinculo, the parties may marry again but when the cause is adultery, the guilty party cannot marry his or her paramour.'),
  8. VALUES ('AB INITIO, from the beginning.');
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: trying to put it all together

 
0
  #9
Apr 6th, 2009
Originally Posted by externalaw View Post
Hi,

I send you a PM with the source and database structure..
Ah. The data are not exactly normalized. That is, each entry does not necessarily meet the 'ALL CAPS' requirement. They're generally ALL CAPS, but some are terminated with space, some with comma, some with period, some with something else.

The script I posted, with a minor change, will probably correctly handle the majority of the entries. But proof reading will still be necessary to ensure the task was done correctly. Also, in skimming a little bit of the data, I noticed a few spots of grammatical nonsense; the data should receive a proper proof-reading anyway.

Give me a few days; I'll see what I can hack together.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: externalaw is an unknown quantity at this point 
Solved Threads: 0
externalaw externalaw is offline Offline
Newbie Poster

Re: trying to put it all together

 
0
  #10
Apr 6th, 2009
Your amazing! Thank you so much!
I will keep my eyes glued to this thread!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC