Determine language of body of text?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark B

    #1

    Determine language of body of text?

    Does anyone have a method to determine the language (e.g. en-US, fr-FR,
    zh-TW etc) of a body of text?

    (In my case the body of text is an email received).

    Naturally the text, if not English, may have a little bit of English. I'm
    just trying to get the main language used.

  • Mark B

    #2
    Re: Determine language of body of text?



    "Mark B" <none123@none.c omwrote in message
    news:u$VCFVONJH A.456@TK2MSFTNG P06.phx.gbl...
    Does anyone have a method to determine the language (e.g. en-US, fr-FR,
    zh-TW etc) of a body of text?
    >
    (In my case the body of text is an email received).
    >
    Naturally the text, if not English, may have a little bit of English. I'm
    just trying to get the main language used.

    Comment

    • MC

      #3
      Re: Determine language of body of text?

      Each language has a few words that are extremely common, such as "the", "a", "an", "of", "for" in English. You could look for the 5 or 10 most common words in each language, and see which language wins.

      To find the most common words, use a word-frequency-table program to analyze some text samples.

      Comment

      • rossum

        #4
        Re: Determine language of body of text?

        On Thu, 23 Oct 2008 20:59:19 +1300, "Mark B" <none123@none.c omwrote:
        >Does anyone have a method to determine the language (e.g. en-US, fr-FR,
        >zh-TW etc) of a body of text?
        >
        >(In my case the body of text is an email received).
        >
        >Naturally the text, if not English, may have a little bit of English. I'm
        >just trying to get the main language used.
        As well as the other suggestions have a look at the characters used:
        umlauts or the ss/beta character appear in German and acute or grave
        accents in French.

        Digram and trigram frequencies can also be a good indicator.

        Essentially you are going to have to use some sort of statistical
        method.

        rossum

        Comment

        • JP

          #5
          Re: Determine language of body of text?

          There's some code here that writes the internet headers of an email to
          a text file, which you could then parse for the language. For example,
          some email headers include a "Content-Type" line which indicates the
          character set used.

          i.e.: Content-Type: text/plain; charset=US-ASCII

          Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


          HTH,
          JP

          On Oct 23, 3:59 am, "Mark B" <none...@none.c omwrote:
          Does anyone have a method to determine the language (e.g. en-US, fr-FR,
          zh-TW etc) of a body of text?
          >
          (In my case the body of text is an email received).
          >
          Naturally the text, if not English, may have a little bit of English. I'm
          just trying to get the main language used.

          Comment

          • Dmitry Streblechenko

            #6
            Re: Determine language of body of text?

            Look at the MailItem.Intern etCodepage property (corresponds to the
            PR_INTERNET_CPI D MAPI propety).

            --
            Dmitry Streblechenko (MVP)
            mapi,cdo,outlook,cdonts,cdoex,IAddrBook,IAttach,IDistList,IMAPIContainer,IMAPIFolder,IMAPIProp,IMAPISession,IMAPIStatus,IMAPI,Table,IMailUser,IMessage,IMsgStore,ThisOutlookSession,calendarview,cdoitem,cdolive,cdowf,hiddenmessages,ifolder,imapifolder,imapiprop,imessage,infostore,infostores,iprofadmin,logonsmtp,mailitem,mapifolder,mapiobject,meetingitem,messages,messagefilter,messagestore,messageview,objectrenderer,officevba,outlookspy,rawtable,recurrencetype,storeid,tableview,Active Messaging,Exchange Server Scripting,attachment object,calendarview,cdosession,collaboration data,entryid,extended,global address list,messaging api,outbox,inbox,outlooktoday,vb,vba,basic,visual basic,delphi,vc,script

            OutlookSpy - Outlook, CDO
            and MAPI Developer Tool
            -
            "Mark B" <none123@none.c omwrote in message
            news:u$VCFVONJH A.456@TK2MSFTNG P06.phx.gbl...
            Does anyone have a method to determine the language (e.g. en-US, fr-FR,
            zh-TW etc) of a body of text?
            >
            (In my case the body of text is an email received).
            >
            Naturally the text, if not English, may have a little bit of English. I'm
            just trying to get the main language used.

            Comment

            • Mark B

              #7
              Re: Determine language of body of text?

              Do all incoming emails have this? Even if they are not originating from an
              Outlook client?

              (It's for an Outlook 2007 Add-in C# BTW).


              "Dmitry Streblechenko" <dmitry@dimastr .comwrote in message
              news:%23$zmqwTN JHA.4172@TK2MSF TNGP06.phx.gbl. ..
              Look at the MailItem.Intern etCodepage property (corresponds to the
              PR_INTERNET_CPI D MAPI propety).
              >
              --
              Dmitry Streblechenko (MVP)
              mapi,cdo,outlook,cdonts,cdoex,IAddrBook,IAttach,IDistList,IMAPIContainer,IMAPIFolder,IMAPIProp,IMAPISession,IMAPIStatus,IMAPI,Table,IMailUser,IMessage,IMsgStore,ThisOutlookSession,calendarview,cdoitem,cdolive,cdowf,hiddenmessages,ifolder,imapifolder,imapiprop,imessage,infostore,infostores,iprofadmin,logonsmtp,mailitem,mapifolder,mapiobject,meetingitem,messages,messagefilter,messagestore,messageview,objectrenderer,officevba,outlookspy,rawtable,recurrencetype,storeid,tableview,Active Messaging,Exchange Server Scripting,attachment object,calendarview,cdosession,collaboration data,entryid,extended,global address list,messaging api,outbox,inbox,outlooktoday,vb,vba,basic,visual basic,delphi,vc,script

              OutlookSpy - Outlook, CDO
              and MAPI Developer Tool
              -
              "Mark B" <none123@none.c omwrote in message
              news:u$VCFVONJH A.456@TK2MSFTNG P06.phx.gbl...
              >Does anyone have a method to determine the language (e.g. en-US, fr-FR,
              >zh-TW etc) of a body of text?
              >>
              >(In my case the body of text is an email received).
              >>
              >Naturally the text, if not English, may have a little bit of English. I'm
              >just trying to get the main language used.
              >
              >

              Comment

              • Dmitry Streblechenko

                #8
                Re: Determine language of body of text?

                Most of them. But that really tells you more about the defaut code page of
                the sender.

                --
                Dmitry Streblechenko (MVP)
                mapi,cdo,outlook,cdonts,cdoex,IAddrBook,IAttach,IDistList,IMAPIContainer,IMAPIFolder,IMAPIProp,IMAPISession,IMAPIStatus,IMAPI,Table,IMailUser,IMessage,IMsgStore,ThisOutlookSession,calendarview,cdoitem,cdolive,cdowf,hiddenmessages,ifolder,imapifolder,imapiprop,imessage,infostore,infostores,iprofadmin,logonsmtp,mailitem,mapifolder,mapiobject,meetingitem,messages,messagefilter,messagestore,messageview,objectrenderer,officevba,outlookspy,rawtable,recurrencetype,storeid,tableview,Active Messaging,Exchange Server Scripting,attachment object,calendarview,cdosession,collaboration data,entryid,extended,global address list,messaging api,outbox,inbox,outlooktoday,vb,vba,basic,visual basic,delphi,vc,script

                OutlookSpy - Outlook, CDO
                and MAPI Developer Tool
                -
                "Mark B" <none123@none.c omwrote in message
                news:%23mASG5UN JHA.276@TK2MSFT NGP02.phx.gbl.. .
                Do all incoming emails have this? Even if they are not originating from an
                Outlook client?
                >
                (It's for an Outlook 2007 Add-in C# BTW).
                >
                >
                "Dmitry Streblechenko" <dmitry@dimastr .comwrote in message
                news:%23$zmqwTN JHA.4172@TK2MSF TNGP06.phx.gbl. ..
                >Look at the MailItem.Intern etCodepage property (corresponds to the
                >PR_INTERNET_CP ID MAPI propety).
                >>
                >--
                >Dmitry Streblechenko (MVP)
                >http://www.dimastr.com/
                >OutlookSpy - Outlook, CDO
                >and MAPI Developer Tool
                >-
                >"Mark B" <none123@none.c omwrote in message
                >news:u$VCFVONJ HA.456@TK2MSFTN GP06.phx.gbl...
                >>Does anyone have a method to determine the language (e.g. en-US, fr-FR,
                >>zh-TW etc) of a body of text?
                >>>
                >>(In my case the body of text is an email received).
                >>>
                >>Naturally the text, if not English, may have a little bit of English.
                >>I'm just trying to get the main language used.
                >>
                >>
                >

                Comment

                • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                  #9
                  Re: Determine language of body of text?

                  Mark B wrote:
                  Does anyone have a method to determine the language (e.g. en-US, fr-FR,
                  zh-TW etc) of a body of text?
                  >
                  (In my case the body of text is an email received).
                  >
                  Naturally the text, if not English, may have a little bit of English.
                  I'm just trying to get the main language used.
                  If you are willing to write some code, then you can detect
                  the language (but probably not the regional dialect).

                  * dictionary with common words
                  * special letters (forward and backward accents, umlauts etc.)
                  * distribution of letters
                  * distribution of pairs of letters

                  Arne

                  Comment

                  Working...