Results 1 to 3 of 3

Thread: need some help on this one

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    toronto
    Posts
    12

    need some help on this one

    hey there

    need some help on a program that i'm trying to create. i've been working on this for over three weeks now. here is what i want to do.

    create a program that offer some word to word translation from english to the language chosen by the user. It could be any language. the user is supposed to type the word in english and the word is supposed to be translated in the other language.
    Also i want to do it using sentences.

    Any help would be appreciated greatly. Just need some idea about how to create the program.

    thank you very much.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: need some help on this one

    I've done something similar as a bilingual dictionary . No much coding requird if it works as dictionary .I'll tell you what I did :

    I've created database with only one table and two fields .Let suppose you have two fields named : English and French .Structure of your table should looks something like this :

    ---------------------------
    English : French :
    ---------------------------
    Hi : Hi
    nice : gentil
    Pirate : Pirate
    boy : garçon
    translate : traduisez

    Now , what are you ganna do ?
    Build your proj with one textbox at least used to type a word in English to be translated into French (either vice versa or both )

    Then , your program looks for this word in english field actually,for instance, if any matches found then show the record combined with it in french . Show the word besides the word in english .If you have done it this way , this results in bilingual dictionary . You need to hire tens of typist either ways lol

    Cheers

  3. #3
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    the following class is an example I banged together for you

    It supposes that you have a database named dictionary.mdb

    the class is very rough but should give you the basic idea

    the db is defined by the following schema

    VB Code:
    1. <?xml version="1.0" encoding="utf-8" ?>
    2. <xs:schema id="dictionary" targetNamespace="http://tempuri.org/dictionary.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/dictionary.xsd" xmlns:mstns="http://tempuri.org/dictionary.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    3.     <xs:element name="Dictionary">
    4.         <xs:complexType>
    5.             <xs:sequence>
    6.                 <xs:element name="DictKey" type="xs:long" />
    7.                 <xs:element name="EngWord" type="xs:string" />
    8.                 <xs:element name="Definition" type="xs:string" />
    9.                 <xs:element name="FrenchWord" type="xs:string" />
    10.             </xs:sequence>
    11.         </xs:complexType>
    12.         <xs:key name="DictionaryKey" msdata:PrimaryKey="true">
    13.             <xs:selector xpath="." />
    14.             <xs:field xpath="mstns:DictKey" />
    15.         </xs:key>
    16.     </xs:element>
    17. </xs:schema>

    the class code is

    VB Code:
    1. Friend Class translateCls
    2.  
    3.     Private Const CONSTRING1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source="
    4.  
    5.     Private Const CONSTRING2 As String = ";Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";" & _
    6.             "Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=" & _
    7.             "5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLED" & _
    8.             "B:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create" & _
    9.             " System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Loc" & _
    10.             "ale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SF" & _
    11.             "P=False"
    12.  
    13.     Protected Enum indexPosition
    14.         FirstWord = 0
    15.         MidString = 1
    16.         LastWord = 2
    17.     End Enum
    18.  
    19.     Dim m_StringToTranslate As String = Nothing
    20.     Dim m_TranslatedString As String = Nothing
    21.  
    22.     Friend Property StringToTranslate() As String
    23.         Get
    24.             Return m_StringToTranslate
    25.         End Get
    26.         Set(ByVal Value As String)
    27.             m_StringToTranslate = Value
    28.         End Set
    29.     End Property
    30.  
    31.     Friend Property TranslatedString() As String
    32.         Get
    33.             Return m_TranslatedString
    34.         End Get
    35.         Set(ByVal Value As String)
    36.             m_TranslatedString = Value
    37.         End Set
    38.     End Property
    39.  
    40.     Protected Friend Shared Function Translate(ByVal originalString As String) As String
    41.         Return Translator(originalString)
    42.     End Function
    43.  
    44.     Protected Friend Sub Translate()
    45.         m_TranslatedString = Translator(m_StringToTranslate)
    46.     End Sub
    47.  
    48.     Protected Shared Function Translator(Optional ByVal originalString As String = "") As String
    49.         Dim stringArray() As String = originalString.Split(" ")
    50.         Dim intLoop As Integer
    51.         Dim NewString As String = originalString
    52.         Dim indexPos As indexPosition = indexPosition.FirstWord
    53.         For intLoop = 0 To stringArray.Length - 1
    54.             If intLoop > 0 And intLoop < stringArray.Length - 1 Then
    55.                 indexPos = indexPosition.MidString
    56.             ElseIf intLoop = stringArray.Length - 1 Then
    57.                 indexPos = indexPosition.LastWord
    58.             End If
    59.             NewString = Replace(NewString, stringArray(intLoop), GetReplaceMentWord(stringArray(intLoop), indexPos))
    60.         Next intLoop
    61.         Return NewString
    62.     End Function
    63.  
    64.     Protected Shared Function Replace(ByVal str As String, ByVal strSearchWord As String, ByVal strReplaceWord As String) As String
    65.         Dim regex As New System.Text.RegularExpressions.Regex("(?i:(" & strSearchWord & "\s)|(\s" & strSearchWord & ")|(" & strSearchWord & "\.)|(" & strSearchWord & ",))")
    66.         str = (regex.Replace(str, strReplaceWord))
    67.         Return str
    68.     End Function
    69.  
    70.  
    71.     Protected Shared Function GetReplaceMentWord(ByVal strWord As String, ByVal position As indexPosition) As String
    72.         Dim dbConn As New OleDb.OleDbConnection(CONSTRING1 & getExeLocation() & "dictionary.mdb" & CONSTRING2)
    73.         Dim strSql As String = "SELECT FrenchWord FROM dictionary WHERE EngWord = '" & strWord & "'"
    74.         Dim dbAdapter As New OleDb.OleDbDataAdapter(strSql, dbConn)
    75.         Dim ods As New DataSet()
    76.  
    77.         dbConn.Open()
    78.         dbAdapter.Fill(ods)
    79.         dbConn.Close()
    80.  
    81.         Dim strNewWord As String = ""
    82.  
    83.         If (Not ods.Tables(0).Rows.Count = 0) Then
    84.             strNewWord = ods.Tables(0).Rows(0).Item("FrenchWord")
    85.         Else
    86.             strNewWord = "?"
    87.         End If
    88.  
    89.         Select Case position
    90.             Case indexPosition.FirstWord
    91.                 strNewWord = strNewWord & " "
    92.             Case indexPosition.MidString
    93.                 strNewWord = " " & strNewWord
    94.             Case indexPosition.LastWord
    95.                 strNewWord = " " & strNewWord
    96.         End Select
    97.         Return strNewWord
    98.     End Function
    99.  
    100.     Protected Shared Function getExeLocation() As String
    101.         Dim strLoc As String = System.Reflection.Assembly.GetExecutingAssembly.Location
    102.         strLoc = strLoc.Remove((strLoc.LastIndexOf("\") + 1), (strLoc.Length - (strLoc.LastIndexOf("\") + 1)))
    103.         Return strLoc
    104.     End Function
    105.  
    106.  
    107. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width