Synonym-Given String

  • Hi All,

    i need to find list of synonyms for a given string using sql server,is there a query to retrive list of synonyms for a given word ?

  • HI,

    Possible, when you create the table and store all the synonyms for the words

    ARUN SAS

  • Hi Arun ,

    Thanks for ur reply, i need to find for (1000s of words) its not possible to find synonym for word by word and store it in a table ???? is it possible dynamically?

    for example :(like built in Function) if we give the word it should generate its list of synonym... guide the query for this???

  • Kavi, could you give us an example of what you are trying to do? Some sample inputs and expected output would be most helpful.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • Hi,

    i have tried synonyms search with full text serach Thesaurus file, but it is needed to predefine the thesaurus file for each word, it is not feasible for me.So, i am looking for alternative option to find the synonyms search for the word.

    For example: i need to find synonyms for any word for eg: the word "check" using sql query then the output should display all synonyms like the list below,

    Try out

    test

    confirm

    ensure

    verify

    prove

    try

    kindly help me with the query to execute this result...

  • Kavi, such a query is simple, but you will still have to define the synonyms. You may be able to search the internet and find some sort of thesaurus file that you could download to populate a synonyms table in your database.

    How do you plan to use this?

    declare @synonyms table

    (rowID int identity (1,1), searchword varchar(20), synonymWord varchar(20)

    primary key (searchword,rowid)

    )

    insert into @synonyms

    select 'check','try out' union all

    select 'check','test' union all

    select 'check','confirm' union all

    select 'check','ensure' union all

    select 'check','verify' union all

    select 'check','try' union all

    select 'check','prove'

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

    select synonymWord

    from @synonyms

    where searchword = 'check'

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • Thanks Bob,

    Still i am trying to search for an pre-filled thesaurus file that defined synonym for all english words...so far not found,

    so wat i tried with some alternate solution,but the query wic u gave doesnt suits me because for word by word i need to insert synonyms its very tedious to insert for whole dictionary ,is there any other way????

  • kavi (3/30/2009)


    Hi All,

    i need to find list of synonyms for a given string using sql server,is there a query to retrive list of synonyms for a given word ?

    [font="Verdana"]Kavi,

    This is not a feature built into SQL Server. It's one you would have to create programmatically. I suggest you go grab a copy of an English Language Thesaurus from your library. If you really want to sit down and encode all of that, then feel free.

    So no, there is no query to retrieve a list of synonyms for a given word. Not unless you build one.

    [/font]

  • Kavi, if you are looking to build your own thesaurus file, you can certainly parse a string of synonyms this way, to make the population easier. This technique could be modified to translate an entire table. If you have questions about this, there are some good articles and forum posts already written under the headings PARSE and TALLY TABLE.

    I hate to leave you now, but it's midnight here and I have to get some sleep. I'll check back in about nine hours.

    I hope this helps.

    declare @synonyms table (rowID int identity (1,1), searchword varchar(20), synonymWord varchar(20)

    primary key (searchword,rowid))

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

    declare @synonym_list varchar(7900)

    declare @sepChar varchar(50)

    declare @element varchar(4)

    declare @searchword varchar(20)

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

    set @searchword = 'check'

    set @synonym_list = 'try out, test, examine, confirm, verify'

    set @sepchar = ','

    set @synonym_list = @sepChar+@synonym_list+@sepChar

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

    ;WITH

    L0 AS (SELECT 1 AS C UNION ALL SELECT 1),--2 rows

    L1 AS (SELECT 1 AS C FROM L0 AS A, L0 AS B),--4 rows "L0 as A, L0 as B" is just shorthand way to code a cross join

    L2 AS (SELECT 1 AS C FROM L1 AS A, L1 AS B),--16 rows

    L3 AS (SELECT 1 AS C FROM L2 AS A, L2 AS B),--256 rows

    L4 AS (SELECT 1 AS C FROM L3 AS A, L3 AS B),--65536 rows

    Tally AS (SELECT TOP 1000 ROW_NUMBER() OVER(ORDER BY C) AS N FROM L4),

    syns AS

    (select Row_Number() over (order by N) as E,

    ltrim(rtrim(substring(@synonym_list,N+1,charindex(@sepChar,@synonym_list,N+1)-(N+1)))) as synWord

    from tally

    where substring(@synonym_list,N,1) = @sepChar

    and N < len(@synonym_list)

    )

    --

    insert into @synonyms

    select @searchword,synword from syns

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

    select *

    from @synonyms

    where searchword = 'check'

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • This is a multiple post. Some discussion has occured at http://www.sqlservercentral.com/Forums/Topic685529-145-1.aspx.

    However, this discussion has developed further.

  • kavi (3/31/2009)


    Hi

    if there is no pre filled thesaurus file with synonyms for all word,is there any alternate solution for my query?

    For example: i need to find synonyms for any word for eg: the word "check" using sql query then the output should display all synonyms like the list below,

    Try out

    test

    ...

    You still haven't told us why you need synonyms.

    Who has asked you to design a query this way?

    Why do they need it to use synonyms?

  • Synonyms? Why would you NOT want synonyms? Of course you want synonyms.

    If someone wants to search for "Natural Language Processing" and types in NLP, do you think they'd be happy if no search results came up because they did not use the exact wording as in the text? To expect the exact words as they appear in the text is way to strict. It creates anxiety for the user. Imagine you asked someone a question and they'd interpret everything you say literally. (We may have done this as a kid.) I am sure you'd avoid such a person pretty quickly.

    Google has used synonyms for years. Didn't you notice?

    And yes, it makes perfect sense to have a default Thesaurus that is a good start for most people. It would save us all a lot of time. And if there are synonyms in there someone does not like, they could remove them. Coming up with all valid synonyms is costly.

    Here is an option: https://github.com/zaibacu/thesaurus (based on WordNet).

    • This reply was modified 2 weeks, 5 days ago by  mschluper.
    • This reply was modified 2 weeks, 5 days ago by  mschluper.

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply