Gossamer Forum
Skip to Content



Home : Products : DBMan : Customization :

how to build a dictionary and do something rather complicated

Quote Reply
how to build a dictionary and do something rather complicated
Hi,

I've got a copy of dbman set up as follows, it's kind of a dictionary thing:

ID,word,plural,synonym,meaning

What I'd like to do here, is in html_record_long that in the 'meaning' field of each record, 'word' 'plural' and 'synonym' are checked of all the (other?) records and if found in it, a link is built to the related records.

I have no problem pattern matching (anymore...) but I'm not sure how to make this work, putting all the words of 3 fields of more or less 300 records in a hash? I guess it's best to start with field 'word' in a hash, check it, followed by the other fields but I might be talking utter nonsense. But I'd need code to look at as I'm not very good yet.

Has anybody ever done this or is there somebody who can give me useful tips?

Thanks,

Lex
Quote Reply
Re: [Lex] how to build a dictionary and do something rather complicated In reply to
Hi,

in terms of structure, what you want to do is to go through the database and return links to all records that have the value $value in the field number $field_num.

This would be one way to do it:

1) In html_record_long, wherever you want to print the link, add this line:

print &other_field_link("$value", "$field_num");

# replace "$value" by e.g. "$rec{word}", and "$field_num" by "23",
# if you want to search for the field value of "word" and if "word" has the field number 23

2) Add this to html.pl or db.cgi

sub other_field_link {
my $value = shift;
my $field_num = shift;
my $link;
open (DB, "<$db_file_name") || &cgierr("Can't open $db_file_name in other_field_link: $!");
while (my $line = <DB>) {
chomp($line);
my @line = &split_decode($line);
if ($line[$field_num] eq "$value") {
$link .= qq|<a href="$db_script_url?db=$db_setup&uid=$db_uid&view_records=1&ID=$line[$db_key_pos]">Nr. $line[$db_key_pos]</a><br>|;

}
close (DB);

if ($link) { return ($link) };

}

This assumes that your db key field is called "ID", and that you may have multiple matches, so you might get several links returned, each printed on a new line.
I haven't tested the syntax.

Let me know whether it works.
kellner
Quote Reply
Re: [kellner] how to build a dictionary and do something rather complicated In reply to
This is great stuff kellner, I'm going to try it out straight away and will let you know what I did with it!

Thanks a lot.

I sincerely think this is something a lot of people could do something with. For example, your database, when showing a record in a certain cetegorie (imagine it's a news db) show the last x records (title only) in the same categorie.

Anyway, I'll let you know my findings.

Cheers!
Quote Reply
Re: [Lex] how to build a dictionary and do something rather complicated In reply to
Hello:

I've added this nice little sub to a few databases and then realized that when the title of the record contains an "&" then the link doesn't display. It works great for all the other records. What I'm using for:

print &other_field_link("$value", "$field_num");

is:

print &other_title_link("$rec{'Title'}", "6");

sub other_title_link {
#----------------------------------------
## this displays other subtitles listed on pages
my $value = shift;
my $field_num = shift;
my $link;
open (DB, "<$db_file_name") || &cgierr("Can't open $db_file_name in other_field_link: $!");
while (my $line = <DB>) {
chomp($line);
my @line = &split_decode($line);

next unless ($line[2] eq 'Yes'); ## Validate field
if ($line[$field_num] eq "$value") {
if ($line[7] ne "") { ## show only if there is a subtitle

$link .= qq|<A HREF="$db_script_link_url&Title=$line[6]&subtitle=$line[7]&ww=1&view_records=1">$line[7]</A><BR>|;
}
}
}
close (DB);

if ($link) {
return ('All Titles on this page:<P>' . $link . '<P>') };
}

Since some records have the same title but different subtitles, I modified the script to just display the subtitles in the list which is $line[7].

Any help would be greatly appreciated :)

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/
Quote Reply
Re: [LoisC] how to build a dictionary and do something rather complicated In reply to
Hi. reading this, I saw I never did as promised. Well, the sub works fine, :) Thanks!

I'm using this dbman on a site that uses a lot of dbmans, and even though I got all the (mayor) text fields in text files, the databases will be getting too big soon. So I have to swap the lot to mysql I think. Now, all this is so heavily modified, that a simple upgrade to dbman mysql won't do the trick. What would the best way be to convert all of this to mysql according to you people?

Last edited by:

Lex: Jul 20, 2008, 3:31 PM
Quote Reply
Re: [LoisC] how to build a dictionary and do something rather complicated In reply to
LoisC wrote:
I've added this nice little sub to a few databases and then realized that when the title of the record contains an "&" then the link doesn't display. It works great for all the other records.
Any help would be greatly appreciated :)

i forgot to say I'm not much of help with your question!

Did you try to see where exactly it goes wrong?
Quote Reply
Re: [Lex] how to build a dictionary and do something rather complicated In reply to
I've never used mysql so can't offer any answers. Perhaps the folks in the DBMan SQL forum can provide some insight into what it would involve.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/
Quote Reply
Re: [LoisC] how to build a dictionary and do something rather complicated In reply to
Well, I emailed Birgit (Kellner) to see if she could help with this. Although she didn't have a solution, she gave me an idea of what the problem could be.

For anyone wanting to use this feature, the problem was that since I was converting the & and " within the record display it was carrying those into sub other_title_link. So the database wasn't able to match those records with the actual db entries.

So I asked in the Programming forum and Andy helped me to write the code to replace those conversions before entering the sub. The solution looks like this in my html_record_long:

if ($rec{'Title'} =~ /\Q&amp;/ || $rec{'Title'}=~ /\Q&quot;/ ) {
$rec{'Title'} =~ s/\&amp; /\& /g;
$rec{'Title'} =~ s/\&quot;/\"/g;
print &other_title_link("$rec{'Title'}", "6");
}
else {
print &other_title_link("$rec{'Title'}", "6");
}

It now works great!

Last edited by:

LoisC: Jul 21, 2008, 12:08 PM
Quote Reply
Re: [LoisC] how to build a dictionary and do something rather complicated In reply to
Thanks for figuring that out! (Or having it figured out ;)