Accessing the Thesaurus in Word 2003 Programmitically in C#

B

BlindCoder

I hope sombody can answe this question...... I've been bangin my head tryin
gto fdind som eosort of sample application that is directly re ferenceing hte
com librbrary for access to the Office 2003 thesaurus results when looking up
a word pregrammicially in a C# application. This SHOULD be simple and as my
Com interopability skills are LOW and I can SEE the results in the VIsual
Studio Debugger as a System.Object returned with Dimestion s (This system.
Object has the Sysnonyms lksited for a word I lookup in the thesaurus.
However, When I call the method: " doc1.Words[1].SynonymInfo.MeaningList" in
C# Code the returned object is System.object I believe HOW CAN I GET THESE
VAULES IN A STRING ARRAY? Do I hafta Cast to somthing from whithin the CVom
oBjects Librbay to get the strings? Can I enumerate the results from System
Object? or need I convert from SYstem.object to System.Object[] ? Sombody
help me.
 
C

Cindy M.

Hi =?Utf-8?B?QmxpbmRDb2Rlcg==?=,
I hope sombody can answe this question...... I've been bangin my head tryin
gto fdind som eosort of sample application that is directly re ferenceing hte
com librbrary for access to the Office 2003 thesaurus results when looking up
a word pregrammicially in a C# application. This SHOULD be simple and as my
Com interopability skills are LOW and I can SEE the results in the VIsual
Studio Debugger as a System.Object returned with Dimestion s (This system.
Object has the Sysnonyms lksited for a word I lookup in the thesaurus.
However, When I call the method: " doc1.Words[1].SynonymInfo.MeaningList" in
C# Code the returned object is System.object I believe HOW CAN I GET THESE
VAULES IN A STRING ARRAY? Do I hafta Cast to somthing from whithin the CVom
oBjects Librbay to get the strings? Can I enumerate the results from System
Object? or need I convert from SYstem.object to System.Object[] ? Sombody
help me.
If you read the Help carefully, you'll see that that data type of the returned
array is a VARIANT. Since the .NET Framework doesn't support this data type, it
converts it to System.Object. This means you have to cast the returned object to
an array. Here's an example

wd.SynonymInfo synInfo = wdDoc.Words[1].SynonymInfo;
object meanings = synInfo.MeaningList;
Array meaningList = (Array) meanings;
MessageBox.Show(String.Format("The term '{0}' has {1} meanings.", testTerm,
meaningList.Length.ToString()));
string allMeanings = "";
foreach (string meaning in meaningList)
{
allMeanings += meaning + "\n";
}
MessageBox.Show(allMeanings);

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
B

BlindCoder

Thank you Cindy for taking the effort to write me this simple responce!. I
almost appologize for asking it cuz the aswer was right in my question (cast
to an array) however, I didn't even know that the object was a Variant type
from the VBA days (of which I have LITTLE experiance with). the Solution is
woroking! I have Strings!.
Now the question is am I doing the right thing for my situation.

Here's the reasoning I wanted these synoyms:

1. I want the fastest way to get english language synonyms for a particualar
word entered or acquired at runtime.

I figured office 2003's thesaurus/dictionary is installed locally on my
machine, so would this be the best resource for synonmys ? OR is Sql Server
2005 (developers edition or other versions) have a thesaurus built-in ? would
it be faster to lookup words programmatically whitin applications? or the
above code you gave me for accessing the comp[onent ? do you know which is
faster/better for my solution? (I prefer to stay in the "managed code/C#/.Net
2.0/VS 2005 world.")

after I know which option is more performant I want to know if I can
excaspolate that functionalitly in a MANAGED .NET librbay Component
application that can be shared by any applications I want to utilise it ?
whether it's from the Office 2004 CXom based thesaurus OR the SQL 2005
thesaurus ?

and one final observation about using the office thesaurus DO I have to make
an application AND a document object just to get these strings synonyms ? is
there a faster more direct way to just get the stringts ?

Thanx again their Cindy if you can answer these well then I"m impressed!

Cindy M. said:
Hi =?Utf-8?B?QmxpbmRDb2Rlcg==?=,
I hope sombody can answe this question...... I've been bangin my head tryin
gto fdind som eosort of sample application that is directly re ferenceing hte
com librbrary for access to the Office 2003 thesaurus results when looking up
a word pregrammicially in a C# application. This SHOULD be simple and as my
Com interopability skills are LOW and I can SEE the results in the VIsual
Studio Debugger as a System.Object returned with Dimestion s (This system.
Object has the Sysnonyms lksited for a word I lookup in the thesaurus.
However, When I call the method: " doc1.Words[1].SynonymInfo.MeaningList" in
C# Code the returned object is System.object I believe HOW CAN I GET THESE
VAULES IN A STRING ARRAY? Do I hafta Cast to somthing from whithin the CVom
oBjects Librbay to get the strings? Can I enumerate the results from System
Object? or need I convert from SYstem.object to System.Object[] ? Sombody
help me.
If you read the Help carefully, you'll see that that data type of the returned
array is a VARIANT. Since the .NET Framework doesn't support this data type, it
converts it to System.Object. This means you have to cast the returned object to
an array. Here's an example

wd.SynonymInfo synInfo = wdDoc.Words[1].SynonymInfo;
object meanings = synInfo.MeaningList;
Array meaningList = (Array) meanings;
MessageBox.Show(String.Format("The term '{0}' has {1} meanings.", testTerm,
meaningList.Length.ToString()));
string allMeanings = "";
foreach (string meaning in meaningList)
{
allMeanings += meaning + "\n";
}
MessageBox.Show(allMeanings);

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)


This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi =?Utf-8?B?QmxpbmRDb2Rlcg==?=,

Well, the proofing tools (spell checker, thesaurus) can only be used within
Office applications. They can't be hooked into for other purposes, or
distributed with your application. So I'd say this approach isn't really the
answer you need for the project you describe.

I have no idea whether SQL Server provides something like this, best place to
ask is in an SQL Server group :)

I'm guessing, unless SQL server provides a thesaurus you can hook into, you'll
need to look for a third-party component that allows programmatic access and
also provides a license for redistribution. Possibly there may be a web-service
you can use?
I figured office 2003's thesaurus/dictionary is installed locally on my
machine, so would this be the best resource for synonmys ? OR is Sql Server
2005 (developers edition or other versions) have a thesaurus built-in ? would
it be faster to lookup words programmatically whitin applications? or the
above code you gave me for accessing the comp[onent ? do you know which is
faster/better for my solution? (I prefer to stay in the "managed code/C#/.Net
2.0/VS 2005 world.")

after I know which option is more performant I want to know if I can
excaspolate that functionalitly in a MANAGED .NET librbay Component
application that can be shared by any applications I want to utilise it ?
whether it's from the Office 2004 CXom based thesaurus OR the SQL 2005
thesaurus ?

and one final observation about using the office thesaurus DO I have to make
an application AND a document object just to get these strings synonyms ? is
there a faster more direct way to just get the stringts ?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
Top