public static AdaptItEncConverter InitLookupAdapter(ProjectSettings proj, GlossType eGlossType)
        {
            EncConverters aECs = new EncConverters();
            string        strName, strConverterSpec;

            ProjectSettings.LanguageInfo liSource, liTarget;
            switch (eGlossType)
            {
            case GlossType.eVernacularToNational:
                strName          = AdaptItLookupConverterName(proj.Vernacular.LangName, proj.NationalBT.LangName);
                strConverterSpec = AdaptItLookupFileSpec(proj.Vernacular.LangName, proj.NationalBT.LangName);
                liSource         = proj.Vernacular;
                liTarget         = proj.NationalBT;
                break;

            case GlossType.eVernacularToEnglish:                        // the glossing KB for the Vern to Natl project
                strName          = AdaptItLookupConverterName(proj.Vernacular.LangName, proj.InternationalBT.LangName);
                strConverterSpec = AdaptItLookupFileSpec(proj.Vernacular.LangName, proj.InternationalBT.LangName);
                liSource         = proj.Vernacular;
                liTarget         = proj.InternationalBT;                 // this is still the national lg project (but the glossing KB)
                break;

            case GlossType.eNationalToEnglish:
                strName          = AdaptItLookupConverterName(proj.NationalBT.LangName, proj.InternationalBT.LangName);
                strConverterSpec = AdaptItLookupFileSpec(proj.NationalBT.LangName, proj.InternationalBT.LangName);
                liSource         = proj.NationalBT;                         // this is a whole nuther national to English project
                liTarget         = proj.InternationalBT;
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                throw new ApplicationException("Wrong glossing type specified. Send to [email protected] for help");
            }

            // just in case the project doesn't exist yet...
            WriteAdaptItProjectFiles(liSource, liTarget, proj.InternationalBT);             // move this to AIGuesserEC project when it's mature.

            // if we don't have the converter already in the repository.
            if (!aECs.ContainsKey(strName))
            {
                aECs.AddConversionMap(strName, strConverterSpec, ConvType.Unicode_to_from_Unicode,
                                      EncConverters.strTypeSILadaptit, "UNICODE", "UNICODE", ProcessTypeFlags.DontKnow);
            }

            IEncConverter aEC = aECs[strName];

            System.Diagnostics.Debug.Assert((aEC != null) && (aEC is AdaptItEncConverter));
            AdaptItEncConverter theLookupAdapter = (AdaptItEncConverter)aEC;

            // in order to get the converter to load the database, do a dummy Convert
            theLookupAdapter.Convert("nothing");
            return(theLookupAdapter);
        }
Example #2
0
        public GlossingForm(ProjectSettings proj, string strSentence, GlossType eGlossType)
        {
            InitializeComponent();

            m_aEC = InitLookupAdapter(proj, eGlossType);

            ProjectSettings.LanguageInfo liSource;
            ProjectSettings.LanguageInfo liTarget;
            switch (eGlossType)
            {
            case GlossType.eVernacularToNational:
                liSource = proj.Vernacular;
                liTarget = proj.NationalBT;
                break;

            case GlossType.eVernacularToEnglish:                        // the glossing KB for the Vern to Natl project
                liSource = proj.Vernacular;
                liTarget = proj.InternationalBT;
                break;

            case GlossType.eNationalToEnglish:
                liSource = proj.NationalBT;
                liTarget = proj.InternationalBT;
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                throw new ApplicationException("Wrong glossing type specified. Send to [email protected] for help");
            }

            // get the EncConverter to break apart the given sentence into bundles
            m_aEC.SplitAndConvert(strSentence, out SourceWords, out StringsInBetween, out TargetWords);
            if (SourceWords.Count == 0)
            {
                throw new ApplicationException("No sentence to gloss!");
            }

            if (liSource.IsRTL)
            {
                flowLayoutPanel.FlowDirection = FlowDirection.RightToLeft;
            }

            System.Diagnostics.Debug.Assert(SourceWords.Count == TargetWords.Count);
            for (int i = 0; i < SourceWords.Count; i++)
            {
                GlossingControl gc = new GlossingControl(this,
                                                         liSource, SourceWords[i],
                                                         liTarget, TargetWords[i],
                                                         StringsInBetween[i + 1]);

                // Bill Martin says that glossing KBs can't have Map greater than 1.
                if (eGlossType == GlossType.eVernacularToEnglish)
                {
                    gc.DisableButton();
                }

                flowLayoutPanel.Controls.Add(gc);
            }

            // disable the button on the last one
            ((GlossingControl)flowLayoutPanel.Controls[flowLayoutPanel.Controls.Count - 1]).DisableButton();
        }