2016-12-05 1 views
-3

나는이 프로그램이 하나의 텍스트 상자에 일반 영어 문장을 가지고 버튼을 클릭하여 텍스트 문장으로 변환하려고 노력하고있다.텍스트 파일로 텍스트 번역기 만들기

단축 할 수있는 단어는 모두 텍스트 파일의 단어로 바뀝니다.

텍스트 파일에서 줄의 예는 52 개 라인 (교체 단어)가 있습니다 NE1

사람이다.

이 문제를 해결하는 가장 좋은 방법은 무엇입니까? 중첩 루프가 가능한 좋은 경로일까요?

나는 많은 경험을하지 못하고 더 많은 언어를 배우려고 노력하며 모든 방법을 시도한다.

다음은 코딩 프로세스를 시작하기 전에 지금까지 내가 어디에서 머리를 쓸지 잘 모르겠다는 것입니다. 텍스트 파일 내에있는 단어 만 바뀌므로 혼자서 발견되지 않는 단어는 무시하고 무시하는 If/Else 문을 사용한다고 생각합니다.

Public Class frmTextese 

Dim inputData() As String = IO.File.ReadAllLines("Textese.txt") 

Private Sub btnTranslate_Click(sender As Object, e As EventArgs) Handles btnTranslate.Click 

    Dim english As Integer = 0 
    Dim englishSentence As String = txtEnglish.Text 

    Dim result() As String 
    result = englishSentence.Split(englishSentence) 

    Dim line As String 
    Dim data() As String 
    For i As Integer = 0 To (inputData.Length - 1) 
     line = inputData(i) 
     data = line.Split(" "c) 
    Next 

    'txtTextese.Text = 

End Sub 

End Class 

내가 달성하기 위해 노력하고있는 무슨의 이미지 :

enter image description here

+0

https://gyazo.com/e30d7f574ef27eb929f7a3097734f5fd – Devin

답변

0

이 시도하고 무슨 일이 일어나고 있는지에 대한 아이디어를 얻을 수있는 의견을 살펴 있습니다. 엄격히 말하면,이 사이트는 코드 작성 서비스가 아니지만 때로는 도움이되지 못한다고 덧붙여 야합니다. 또한 단어의 대소 문자 및 단어 뒤에 나오는 구두점을 고려합니다. 약간 빠르고 빠르지 만 기본 사항에서는 제대로 작동하는 것 같습니다.

Public Class frmTextese 
    'create a new empty dictionary where we'll add the pairs of english and 
    'textese words 
    Dim englishToTextese As New Dictionary(Of String, String) 
    Private Sub frmTextese_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     'load textese dictionary to an array 
     Dim filedata() As String = IO.File.ReadAllLines("k:\textese.txt") 
     'Split each line into its elements and add to the dictionary 
     For Each item As String In filedata 
      Dim splitstring() As String = item.Split(","c) 
      englishToTextese.Add(splitstring(0), splitstring(1)) 
     Next 
    End Sub 

    Private Function IsCapitalized(word As String) As Boolean 
     'If the first character in the word is upper case then return true 
     'else return false 
     If Mid(word, 1, 1) = Mid(word, 1, 1).ToUpper Then 
      Return True 
     Else 
      Return False 
     End If 
    End Function 

    Private Function GetPunctuation(word As String) As Tuple(Of String, String) 
     'If the last character in the word is a punctuation mark, return a pair of values which are : 
     'the word without puctuation, and the punctuation. Else 
     'return the word and an empty string 
     Dim result As Tuple(Of String, String) 
     If "!':;?/.,".Contains(word.Last()) Then 
      result = New Tuple(Of String, String)(Mid(word, 1, word.Length - 1), word.Last) 
     Else 
      result = New Tuple(Of String, String)(word, "") 
     End If 
     Return result 
    End Function 

    Private Sub btnTranslate_Click(sender As Object, e As EventArgs) Handles btnTranslate.Click 
     Dim textese As String = "" 
     'split the text in the txtEnglish textbox into its component words including any punctuation 
     Dim words() As String = txtEnglish.Text.Split(" "c) 
     For Each englishWord As String In words 
      'get the word and any punctuation following it as a pair of items 
      'and store in punctResult 
      Dim punctResult As Tuple(Of String, String) = GetPunctuation(englishWord) 
      Dim texteseWord As String 
      'store the first item (the word) in englishWord 
      englishWord = punctResult.Item1 
      'store the secont item (the punctuation or a blank string) in punctuation 
      Dim punctuation As String = punctResult.Item2 
      'If the english word is in the dictionary 
      If englishToTextese.ContainsKey(englishWord.ToLower) Then 
       'get the textesevertion 
       texteseWord = englishToTextese(englishWord.ToLower) 
       'if the original english word was capiutalized, capitalize the textese word 
       If IsCapitalized(englishWord) Then 
        texteseWord = texteseWord.ToUpperInvariant 
       End If 
       'add the word to the textese sentence 
       textese = textese & texteseWord & punctuation & " " 
      Else 
       'if the word isn't in the dictionary, add the original english word and its original state 
       'of capitalization and punctuation to the textese sentence 
       textese = textese & englishWord & punctuation & " " 
      End If 
     Next 
     'store the new texteze sentence in the textbox 
     txtTextese.Text = textese 
    End Sub 

End Class 
관련 문제