943,837 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Apr 5th, 2009
0

trying to put it all together

Expand Post »
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,

Quote ...
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
externalaw is offline Offline
13 posts
since Apr 2009
Apr 5th, 2009
0

Re: trying to put it all together

I'm not sure what you mean by in a column... in a text file?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Apr 5th, 2009
0

Re: trying to put it all together

Click to Expand / Collapse  Quote originally posted by Comatose ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
externalaw is offline Offline
13 posts
since Apr 2009
Apr 5th, 2009
0

Re: trying to put it all together

Ah, ok... so in the new text file, you want it Tab delimited... so the upper case words <tab> definition. K.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Apr 5th, 2009
0

Re: trying to put it all together

Click to Expand / Collapse  Quote originally posted by Comatose ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
externalaw is offline Offline
13 posts
since Apr 2009
Apr 6th, 2009
0

Re: trying to put it all together

Click to Expand / Collapse  Quote originally posted by externalaw ...
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
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Apr 6th, 2009
0

Re: trying to put it all together

Hi,

I send you a PM with the source and database structure..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
externalaw is offline Offline
13 posts
since Apr 2009
Apr 6th, 2009
0

Re: trying to put it all together

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.');
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Apr 6th, 2009
0

Re: trying to put it all together

Click to Expand / Collapse  Quote originally posted by externalaw ...
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.
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Apr 6th, 2009
0

Re: trying to put it all together

Your amazing! Thank you so much!
I will keep my eyes glued to this thread!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
externalaw is offline Offline
13 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: question on using awk/gawk
Next Thread in Shell Scripting Forum Timeline: beginner help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC