Exemplo n.º 1
0
        public WordCollection(Word.Words sentence, ErrorList errors, int sentenceNumber)
        {
            this.sentence = sentence;
            this.errorList = errors;
            this.sentenceNumber = sentenceNumber;
            this.wordUnderline = new Word.WdUnderline[sentence.Count];
            this.wordColor = new Word.WdColor[sentence.Count];

            markWordsIfError();
        }
Exemplo n.º 2
0
        /**
         * This is the main function that checks for grammar errors.
         **/
        public void insertText()
        {
            //Test lines to parse
            //Bráðum koma jólin. Eða er það ekki? Jú víst.
            //Hún er góði kennarans. Hann er stór strákar. Hún er góð kennari. Hún er góður. Hún hljóp í gegnum skóginum. Hann borðuðu mikið.

            //Check if there is a selected text to parse, if not then we take all document.
            Word.Selection currentSelection = Application.Selection;
            Sentences sentencesToParse;
            if (!currentSelection.Text.Equals("\r"))
            {
                sentencesToParse = currentSelection.Sentences;
            }
            else
            {
                sentencesToParse = Doc.Sentences;
            }

            //For each sentance we run it through iceparser and keep track of errors.
            for (int sentenceNumber = 1; sentenceNumber < sentencesToParse.Count + 1; sentenceNumber++)
            {
                string textToParse = sentencesToParse[sentenceNumber].Text;

                 //Setup the process with the ProcessStartInfo class.
                ProcessStartInfo start = new ProcessStartInfo();
                //TODO: Athuga afhverju environment stillingar koma ekki inn. (java finnst ekki nema ég gefi fullan path) We need another way to start this.
                start.FileName = @"C:\Program Files\Java\jre6\bin\javaw.exe"; // Specify exe file.
                start.Arguments = "-jar C:\\malvinnsla\\Malgrylan\\GrylanGit\\Grylan\\build\\jar\\Gryla.jar \"" + textToParse + "\"";
                start.UseShellExecute = false;
                start.RedirectStandardOutput = true;

                //Variable that gets the result.
                string result = "";
                // Start the process.
                using (Process process = Process.Start(start))
                {
                    // Read in all the text from the process with the StreamReader.
                    using (StreamReader reader = process.StandardOutput)
                    {
                        result = reader.ReadToEnd();
                        ////Print out the error list. (for debuging purpose).
                        //System.Windows.Forms.MessageBox.Show("Villulisti:\n" + result);
                    }
                }

                ////TODO: Ask the socket and get the reslt.
                //ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9090);
                //server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                //string result = "";
                //try
                //{
                //    server.Connect(ipep);
                //    ns = new NetworkStream(server);
                //    sr = new StreamReader(ns,Encoding.UTF8);
                //    sw = new StreamWriter(ns, Encoding.UTF8);
                //    sw.AutoFlush = true;
                //    textToParse = "1" + textToParse;//We use 1 at start to say that this is a  request. 0 shuts down the socket server.
                //    //sw.WriteLine(Encoding.UTF8.GetBytes(textToParse));
                //    sw.WriteLine(textToParse);

                //    //sw.Flush();

                //    int hvadaStatusErNuna = 0;

                //    //if (sr.Peek() >= 0)
                //    //{
                //        result = sr.ReadLine();
                //    //}
                //    //result = sr.ReadToEnd().ToString();

                //    if (sw != null)
                //        sw.Close();
                //    if (sr != null)
                //        sr.Close();
                //    if (ns != null)
                //        ns.Close();
                //    if (server.Connected == true)
                //    {
                //        server.Shutdown(SocketShutdown.Both);
                //        server.Close();
                //    }
                //}
                //catch (SocketException se)
                //{
                //    System.Windows.Forms.MessageBox.Show("Unable to connect to socket:\n" + se.ToString());
                //    return;
                //}

                //ErrorList collects all WordErrors with its parameters (number of word, the word, rulenumber and suggestions)
                ErrorList errorList = new ErrorList();
                if (!result.Equals("") && !result.StartsWith("ok"))
                {
                    //For each line in result we create an error and put it on the ErrorList.
                    errorList.add(parseResult(result));
                }

                //Create the sentence class instance, Values are: an array of words, List of errors, number of the sentance.
                WordCollection sentence = new WordCollection(sentencesToParse[sentenceNumber].Words, errorList, sentenceNumber);
                sentences.Add(sentence);
                foreach (WordError we in errorList.getErrorList())
                {
                    allErrors.Add(we);
                }

            }
            displayErrors(allErrors);
        }