dbTalk Databases Forums  

Query has me stumped

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Query has me stumped in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
markdavies2003@msn.com
 
Posts: n/a

Default Query has me stumped - 07-12-2007 , 01:24 PM






Assume the following table, where the columns represent two-word
strings (word1 and word2) and the part of speech of the second word,
along with their frequency:

[TagTable]

freq word1 word2 partOfSpeechWord2
---- ---- ---- ----
1 the plant verb (incorrectly tagged)
21 the plant noun
6 to plant verb
27 to stop verb
3 to stop noun (incorrectly tagged)
4 the stop noun

I want to generate the following list, which show the most frequent
partOfSpeech for a given word1 / word2 combination, e.g.:

21 the plant noun
6 to plant verb
27 to stop verb
4 the stop noun

(but would not include the following, which are presumably errors from
a part of speech tagger):
1 the plant verb
3 to stop noun

What's the SELECT command to get the four correct results above?

----------------------------------------

A somewhat more complicated scenario --

Assume the same [TagTable] above, and then another table with NULL
partOfSpeech tags:

[NeedsTag]

word1 word2 partOfSpeechWord2
---- ---- ----
the plant NULL
to plant NULL
to stop NULL
the stop NULL

What would be the correct UPDATE command to insert noun, verb, verb,
noun (in that order) into this table, based on the most frequent tag
from the first table (i.e. ignoring the incorrect "the plant = V" and
"to stop = N")?

Thanks in advance for your help.

Mark Davies


Reply With Quote
  #2  
Old   
Roy Harvey
 
Posts: n/a

Default Re: Query has me stumped - 07-12-2007 , 03:49 PM






The query:

SELECT A.*
FROM TagTable as A
WHERE partOfSpeechWord2 =
(SELECT TOP 1 B.partOfSpeechWord2
FROM TagTable as B
WHERE A.word1 = B.word1
AND A.word2 = B.word2
ORDER BY B.freq desc)

And the update, which includes the above query as a derived table.

UPDATE NeedsTag
SET partOfSpeechWord2 = X.partOfSpeechWord2
FROM (SELECT A.*
FROM TagTable as A
WHERE partOfSpeechWord2 =
(SELECT TOP 1 B.partOfSpeechWord2
FROM TagTable as B
WHERE A.word1 = B.word1
AND A.word2 = B.word2
ORDER BY B.freq desc)) as X
WHERE NeedsTag.word1 = X.word1
AND NeedsTag.word2 = X.word2

Roy Harvey
Beacon Falls, CT

On Thu, 12 Jul 2007 11:24:54 -0700, markdavies2003 (AT) msn (DOT) com wrote:

Quote:
Assume the following table, where the columns represent two-word
strings (word1 and word2) and the part of speech of the second word,
along with their frequency:

[TagTable]

freq word1 word2 partOfSpeechWord2
---- ---- ---- ----
1 the plant verb (incorrectly tagged)
21 the plant noun
6 to plant verb
27 to stop verb
3 to stop noun (incorrectly tagged)
4 the stop noun

I want to generate the following list, which show the most frequent
partOfSpeech for a given word1 / word2 combination, e.g.:

21 the plant noun
6 to plant verb
27 to stop verb
4 the stop noun

(but would not include the following, which are presumably errors from
a part of speech tagger):
1 the plant verb
3 to stop noun

What's the SELECT command to get the four correct results above?

----------------------------------------

A somewhat more complicated scenario --

Assume the same [TagTable] above, and then another table with NULL
partOfSpeech tags:

[NeedsTag]

word1 word2 partOfSpeechWord2
---- ---- ----
the plant NULL
to plant NULL
to stop NULL
the stop NULL

What would be the correct UPDATE command to insert noun, verb, verb,
noun (in that order) into this table, based on the most frequent tag
from the first table (i.e. ignoring the incorrect "the plant = V" and
"to stop = N")?

Thanks in advance for your help.

Mark Davies

Reply With Quote
  #3  
Old   
--CELKO--
 
Posts: n/a

Default Re: Query has me stumped - 07-12-2007 , 09:29 PM



Quote:
Assume the following table, where the columns represent two-word strings (word1 and word2) and the part of speech of the second word, along with their frequency:
Since the part of speech coumn is computed from word1, why does it
exist at all? Put it in a VIEW.



Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.