Пример #1
0
		public LexemeKey(LexemeType type, string lexicalForm, int homograph)
		{
			Debug.Assert(lexicalForm.IsNormalized(), "Key lexical forms should always be in composed form");

			m_type = type;
			m_lexicalForm = lexicalForm;
			m_homograph = homograph;
		}
Пример #2
0
		public LexemeKey(string id)
		{
			Match match = s_idRegex.Match(id);
			Debug.Assert(match.Groups[2].Value.IsNormalized(), "Key lexical forms should always be in composed form");
			m_type = (LexemeType)Enum.Parse(typeof(LexemeType), match.Groups[1].Value);
			m_lexicalForm = match.Groups[2].Value;
			m_homograph = match.Groups[3].Length > 0 ? Int32.Parse(match.Groups[3].Value.Substring(1), CultureInfo.InvariantCulture) : 1;
		}
Пример #3
0
        private State AddState(LexemeType name, bool isTerminal)
        {
            if (mStatesByName.ContainsKey(name))
            {
                return(mStatesByName[name]);
            }
            var st = new State(name, isTerminal);

            mStates.Add(st);
            mStatesByName.Add(name, st);
            return(st);
        }
Пример #4
0
        public void AddArray(LexemeType fromState, LexemeType toState, char[] chars, bool isTerminal, bool hasValue,
                             string prefix = "", string suffix = "")
        {
            State st1 = fromState == LexemeType.NONE ? mStartState : AddState(fromState, false);

            State st2 = toState == LexemeType.NONE ? mErrorState : AddState(toState, isTerminal);

            foreach (char ch in chars)
            {
                AddTransition(st1, st2, ch, hasValue ? (st2 == mErrorState ? prefix : (prefix + ch + suffix)) : null);
            }
        }
Пример #5
0
        private Lexeme AdvanceBufferForSpecifiedLexemeType(LexemeType type)
        {
            var match = LexemeRegexLookup.Map[type].Match(_buffer);

            if (!match.Success || match.Index != 0)
            {
                return(new Lexeme(LexemeType.Undefined, null));
            }

            _buffer = _buffer.Remove(0, match.Length);
            return(new Lexeme(type, match.Value));
        }
    public void Ctor_WhenCalled_ShouldInitializeAllFields()
    {
        LexemeType expectedType  = LexemeType.Do;
        object     expectedValue = "Hello";
        int        expectedLine  = 9;

        var sut = CreateSut(expectedType, expectedValue, expectedLine);

        sut.Type.Should().Be(expectedType);
        sut.Value.Should().BeSameAs(expectedValue);
        sut.LineNumber.Should().Be(expectedLine);
    }
Пример #7
0
        /// <summary>
        /// true, если переданный тип является нечетким или целочисленным значением, false - в противном случае
        /// </summary>
        /// <param name="lexemeType">Тип лексемы</param>
        public static bool IsValue(LexemeType lexemeType)
        {
            switch (lexemeType)
            {
            case LexemeType.IntValue:
            case LexemeType.FuzzyValue:
                return(true);

            default:
                return(false);
            }
        }
Пример #8
0
 public Lexeme FindOrCreateLexeme(LexemeType type, string lexicalForm)
 {
     using (m_activationContext.Activate())
     {
         Lexeme lexeme;
         if (!TryGetLexeme(new LexemeKey(type, lexicalForm), out lexeme))
         {
             lexeme = CreateLexeme(type, lexicalForm);
         }
         return(lexeme);
     }
 }
Пример #9
0
        public Lexeme(LexemeType type, string val, int line, int column)
        {
            this.Type = type;

            if(val != null)
                this.Value = val;
            else
                this.Value = null;

            this.Line = line;
            this.Column = column;
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds a new sense to the lexeme with the specified information
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public LexSense AddSenseToEntry(LexemeType type, string lexicalForm, int homograph)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();
            Logger.WriteEvent("Adding new sense to lexeme '" + lexicalForm + "' from an external application");

            return(NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                string guid = string.Empty;
                switch (type)
                {
                case LexemeType.Word:
                    {
                        IWfiWordform dbWordform = GetDbWordform(lexicalForm);
                        if (dbWordform == null)
                        {
                            throw new ArgumentException("Entry in the lexicon not found for the specified information");
                        }

                        // For wordforms, our "senses" could be new meanings of an analysis for the word
                        // or it could be a brand new analysis. Because we have no idea what the user actually
                        // wanted, we just assume the worst (they want to create a new analysis for the word
                        // with a new meaning).
                        IWfiAnalysis dbAnalysis = m_cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create();
                        dbWordform.AnalysesOC.Add(dbAnalysis);
                        guid = kAnalysisPrefix + dbAnalysis.Guid;
                        break;
                    }

                default:
                    {
                        ILexEntry dbEntry = GetDbLexeme(type, lexicalForm, homograph);
                        if (dbEntry == null)
                        {
                            throw new ArgumentException("Entry in the lexicon not found for the specified information");
                        }

                        if (dbEntry.SensesOS.Count == 1 && dbEntry.SensesOS[0].Gloss.StringCount == 0)
                        {
                            // An empty sense exists (probably was created during a call to AddLexeme)
                            guid = dbEntry.SensesOS[0].Guid.ToString();
                            break;
                        }

                        ILexSense newSense = m_cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(
                            dbEntry, new SandboxGenericMSA(), null);
                        guid = newSense.Guid.ToString();
                        break;
                    }
                }
                return new LexSense(guid);
            }));
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the DB LexEntry for the specified type and form (homograph currently ignored) or
        /// null if none could be found.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private ILexEntry GetDbLexeme(LexemeType type, string lexicalForm, int homograph)
        {
            if (type == LexemeType.Word)
            {
                throw new ArgumentException("LexEntry can not be found for the Lexeme type specified");
            }

            // ENHANCE: We may have to do something with the homograph number eventually, but
            // currently there is no correlation between the homograph number in the DB and
            // the homograph number passed from the external application.
            return(m_cache.ServiceLocator.GetInstance <ILexEntryRepository>().GetHomographs(lexicalForm).FirstOrDefault(
                       dbEntry => LexemeTypeAndMorphTypeMatch(type, dbEntry.PrimaryMorphType)));
        }
Пример #12
0
        public Lexeme(LexemeType type, string value, int line, int start, int length)
            : base(PhraseType.UnknownLexeme)
        {
            base.Start  = start;
            base.Length = length;
            base.Line   = line;

            base.Value = null;
            base.Level = 0;
            //    this.Value.Add(lexeme);

            this.LType  = type;
            this.LValue = value;
        }
Пример #13
0
        public void FillRemaining(LexemeType fromState, LexemeType toState, bool isTerminal, bool hasValue, string prefix = "", string suffix = "")
        {
            State st1 = fromState == LexemeType.NONE ? mStartState : AddState(fromState, false);

            State st2 = toState == LexemeType.NONE ? mErrorState : AddState(toState, isTerminal);

            for (char ch = '\0'; ch < 256; ch++)
            {
                if (st1.Transitions[ch]?.Item1 == null)
                {
                    AddTransition(st1, st2, ch, hasValue ? (st2 == mErrorState ? prefix : (prefix + ch + suffix)) : null, false);
                }
            }
        }
Пример #14
0
        public bool ReadNext()
        {
            if (position >= paletteString.Length)
            {
                return(false);
            }
            while (paletteString[position] == ' ')
            {
                position++;
            }

            if (paletteString[position] == '#' || Char.IsLetter(paletteString[position]))
            {
                currentLexem = LexemeType.Color;
                int start = position;
                while (position < paletteString.Length && paletteString[position] != ' ' &&
                       paletteString[position] != '=' && paletteString[position] != ',')
                {
                    position++;
                }
                string color = paletteString.Substring(start, position - start);
                valueColor = GetColorFromString(color);
            }
            else if (paletteString[position] == '=' || paletteString[position] == ',')
            {
                currentLexem = LexemeType.Separator;
                if (paletteString[position] == '=')
                {
                    valueSeparator = Separator.Equal;
                }
                else
                {
                    valueSeparator = Separator.Comma;
                }
                position++;
            }
            else
            {
                currentLexem = LexemeType.Number;
                int start = position;
                while (position < paletteString.Length && paletteString[position] != ' ' &&
                       paletteString[position] != '=' && paletteString[position] != ',')
                {
                    position++;
                }
                string number = paletteString.Substring(start, position - start);
                valueNumber = Double.Parse(number, CultureInfo.InvariantCulture);
            }
            return(true);
        }
Пример #15
0
        public Lexeme GetNextLexemeFromBuffer(LexemeType specifiedLexeme = LexemeType.Unspecified)
        {
            if (_buffer.Length == 0)
            {
                return(new Lexeme(LexemeType.Eof, string.Empty));
            }

            if (specifiedLexeme == LexemeType.Unspecified)
            {
                return(AdvanceBufferForUnspecifiedLexemeType());
            }

            return(AdvanceBufferForSpecifiedLexemeType(specifiedLexeme));
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Looks up an lexeme
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public LexicalEntry GetLexeme(LexemeType type, string lexicalForm, int homograph)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();

            switch (type)
            {
            case LexemeType.Word:
                IWfiWordform wf = GetDbWordform(lexicalForm);
                return((wf != null) ? CreateEntryFromDbWordform(wf) : null);

            default:
                ILexEntry dbEntry = GetDbLexeme(type, lexicalForm, homograph);
                return((dbEntry != null) ? CreateEntryFromDbEntry(type, dbEntry) : null);
            }
        }
Пример #17
0
 private bool TryPopRegex(Regex r, LexemeType type, out Lexeme lexeme)
 {
     if (TryMatch(r, out Match match))
     {
         this.pos += match.Length;
         lexeme    = new Lexeme(type, match.Value);
         lexemes.Add(lexeme);
         return(true);
     }
     else
     {
         lexeme = null;
         return(false);
     }
 }
Пример #18
0
        private State AddStringState(LexemeType name, string str, bool isTerminal)
        {
            if (mStatesByStr.ContainsKey(str))
            {
                if (isTerminal)
                {
                    mStatesByStr[str].IsTerminal = true;
                    mStatesByStr[str].Name       = name;
                }
                return(mStatesByStr[str]);
            }
            var st = new State(name, isTerminal);

            mStates.Add(st);
            mStatesByStr.Add(str, st);
            return(st);
        }
Пример #19
0
        /// <summary>
        /// true, если переданный тип является операцией, false - в противном случае
        /// </summary>
        /// <param name="lexemeType">Тип лексемы</param>
        public static bool IsOperation(LexemeType lexemeType)
        {
            switch (lexemeType)
            {
            case LexemeType.And:
            case LexemeType.Or:
            case LexemeType.Equal:
            case LexemeType.NotEqual:
            case LexemeType.More:
            case LexemeType.MoreOrEqual:
            case LexemeType.Less:
            case LexemeType.LessOrEqual:
                return(true);

            default:
                return(false);
            }
        }
Пример #20
0
        public Lexeme CreateLexeme(LexemeType type, string lexicalForm)
        {
            if (type == LexemeType.Word)
            {
                return(new FdoWordformLexeme(this, new LexemeKey(type, lexicalForm)));
            }

            int num = 1;

            foreach (ILexEntry entry in GetMatchingEntries(type, lexicalForm))
            {
                if (m_homographNumbers.GetOrCreateValue(entry).Number != num)
                {
                    break;
                }
                num++;
            }

            return(new FdoLexEntryLexeme(this, new LexemeKey(type, lexicalForm, num)));
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the morph type for the specified lexeme type.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private IMoMorphType GetMorphTypeForLexemeType(LexemeType type)
        {
            if (type == LexemeType.Word || type == LexemeType.Lemma)
            {
                throw new ArgumentException("Morph type can never be of the specified lexeme type");
            }

            IMoMorphTypeRepository repo = m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>();

            switch (type)
            {
            case LexemeType.Prefix: return(repo.GetObject(MoMorphTypeTags.kguidMorphPrefix));

            case LexemeType.Suffix: return(repo.GetObject(MoMorphTypeTags.kguidMorphSuffix));

            case LexemeType.Phrase: return(repo.GetObject(MoMorphTypeTags.kguidMorphPhrase));

            case LexemeType.Stem: return(repo.GetObject(MoMorphTypeTags.kguidMorphStem));
            }
            return(null);
        }
Пример #22
0
        private void CreateEntryIndexIfNeeded()
        {
            if (m_entryIndex != null)
            {
                return;
            }

            m_entryIndex = new Dictionary <LexemeKey, SortedSet <ILexEntry> >();
            foreach (ILexEntry entry in m_cache.ServiceLocator.GetInstance <ILexEntryRepository>().AllInstances())
            {
                LexemeType type = GetLexemeTypeForMorphType(entry.PrimaryMorphType);
                string     form = entry.LexemeFormOA == null ? string.Empty : entry.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text ?? string.Empty;
                var        key  = new LexemeKey(type, form.Normalize());

                SortedSet <ILexEntry> entries;
                if (!m_entryIndex.TryGetValue(key, out entries))
                {
                    entries           = new SortedSet <ILexEntry>(m_entryComparer);
                    m_entryIndex[key] = entries;
                }

                HomographNumber hn = m_homographNumbers.GetOrCreateValue(entry);
                if (hn.Number == 0)
                {
                    int num = 1;
                    foreach (ILexEntry e in entries)
                    {
                        if (m_homographNumbers.GetOrCreateValue(e).Number != num)
                        {
                            break;
                        }
                        num++;
                    }
                    hn.Number = num;
                }

                entries.Add(entry);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new LexicalEntry from the specified lexical entry in the DB
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private LexicalEntry CreateEntryFromDbEntry(LexemeType type, ILexEntry dbEntry)
        {
            if (type == LexemeType.Word)
            {
                throw new ArgumentException("Lexeme type specified can not be created from a LexEntry");
            }

            // A homograph number of zero in the DB means there is only one entry for the wordform.
            // However, the interface requires there be an entry with a homograph of one even if
            // there is only one entry.
            LexicalEntry entry = new LexicalEntry(type, dbEntry.HomographForm,
                                                  dbEntry.HomographNumber > 0 ? dbEntry.HomographNumber : 1);

            // Add the senses to the interface (non-DB) entry
            foreach (ILexSense dbSense in dbEntry.SensesOS)
            {
                LexSense sense = new LexSense(dbSense.Guid.ToString());
                AddDbGlossesToSense(sense, dbSense.Gloss);
                entry.Senses.Add(sense);                 // Add the sense to the list of senses
            }
            return(entry);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds a new gloss to the sense with the specified information
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public LexGloss AddGlossToSense(LexemeType type, string lexicalForm, int homograph,
                                        string senseId, string language, string text)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();
            Logger.WriteEvent("Adding new gloss to lexeme '" + lexicalForm + "' from an external application");

            return(NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                IMultiUnicode dbGlosses;
                if (senseId.StartsWith(kAnalysisPrefix))
                {
                    // The "sense" is actually an analysis for a wordform and our new
                    // gloss is a new meaning for that analysis.
                    Guid analysisGuid = new Guid(senseId.Substring(kAnalysisPrefix.Length));
                    IWfiAnalysis dbAnalysis = m_cache.ServiceLocator.GetInstance <IWfiAnalysisRepository>().GetObject(analysisGuid);
                    IWfiGloss dbGloss = dbAnalysis.MeaningsOC.FirstOrDefault();
                    if (dbGloss == null)
                    {
                        dbGloss = m_cache.ServiceLocator.GetInstance <IWfiGlossFactory>().Create();
                        dbAnalysis.MeaningsOC.Add(dbGloss);
                    }
                    dbGlosses = dbGloss.Form;
                    dbAnalysis.ApprovalStatusIcon = 1;                             // Assume the analysis from the external application is user approved
                }
                else
                {
                    Guid senseGuid = new Guid(senseId);
                    ILexSense dbSense = m_cache.ServiceLocator.GetInstance <ILexSenseRepository>().GetObject(senseGuid);
                    dbGlosses = dbSense.Gloss;
                }

                // Add the new gloss to the list of glosses for the sense
                ILgWritingSystem writingSystem = m_cache.WritingSystemFactory.get_Engine(language);
                dbGlosses.set_String(writingSystem.Handle, TsStringUtils.MakeTss(text, writingSystem.Handle));

                return new LexGloss(language, text);
            }));
        }
Пример #25
0
        public new static void Parse(Parser parser, int basePriority)
        {
            switch (parser.Analyser.Peek().Type)
            {
            case LexemeType.add:
            case LexemeType.sub:
            case LexemeType.mul:
            case LexemeType.div:
                break;

            default:
                throw new InvalidOperationException("Ожидается арифметическое действие!");
            }
            Lexeme     lexeme    = parser.Analyser.Peek();
            LexemeType operation = parser.Analyser.Read().Type;

            Expression.Parse(parser, lexeme.GetPriority());
            switch (operation)
            {
            case LexemeType.add:
                parser.ParseStack.Push(new Addition((Expression)parser.ParseStack.Pop(), (Expression)parser.ParseStack.Pop()));
                break;

            case LexemeType.sub:
                Expression op1 = (Expression)parser.ParseStack.Pop();
                parser.ParseStack.Push(new Substract((Expression)parser.ParseStack.Pop(), op1));
                break;

            case LexemeType.mul:
                parser.ParseStack.Push(new Multiplication((Expression)parser.ParseStack.Pop(), (Expression)parser.ParseStack.Pop()));
                break;

            case LexemeType.div:
                Expression op2 = (Expression)parser.ParseStack.Pop();
                parser.ParseStack.Push(new Division((Expression)parser.ParseStack.Pop(), op2));
                break;
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Determines if the specified lexeme type matches the specified morph type
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static bool LexemeTypeAndMorphTypeMatch(LexemeType type, IMoMorphType morphType)
        {
            if (type == LexemeType.Word || type == LexemeType.Lemma)
            {
                throw new ArgumentException("Morph type can never be of the specified lexeme type");
            }

            switch (type)
            {
            case LexemeType.Prefix: return(morphType.IsPrefixishType);

            case LexemeType.Suffix: return(morphType.IsSuffixishType);

            case LexemeType.Stem: return(morphType.IsStemType &&
                                         morphType.Guid != MoMorphTypeTags.kguidMorphPhrase &&
                                         morphType.Guid != MoMorphTypeTags.kguidMorphDiscontiguousPhrase);

            case LexemeType.Phrase:
                return(morphType.Guid == MoMorphTypeTags.kguidMorphPhrase ||
                       morphType.Guid == MoMorphTypeTags.kguidMorphDiscontiguousPhrase);
            }
            return(false);
        }
        /// <summary>
        /// Метод получения приоритета типа лексемы.
        /// Возвращает приоритет типа лексемы - целое число от 0 до 3
        /// </summary>
        /// <param name="lexemeType"></param>
        private static byte GetPriority(LexemeType lexemeType)
        {
            switch (lexemeType)
            {
            case LexemeType.OpenBracket:
            case LexemeType.CloseBracket:
                return(0);

            case LexemeType.Equal:
            case LexemeType.NotEqual:
            case LexemeType.More:
            case LexemeType.MoreOrEqual:
            case LexemeType.Less:
            case LexemeType.LessOrEqual:
                return(1);

            case LexemeType.And:
            case LexemeType.Or:
                return(2);

            default:
                return(3);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Removes the gloss with the specified language form the sense with the specified information
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void RemoveGloss(LexemeType type, string lexicalForm, int homograph,
                                string senseId, string language)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();
            Logger.WriteEvent("Removing gloss from lexeme '" + lexicalForm + "' from an external application");

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                IMultiUnicode dbGlosses;
                Guid guid;
                if (senseId.StartsWith(kAnalysisPrefix))
                {
                    // The "sense" is actually an analysis for a wordform and the gloss
                    // we want to delete is a meaning for that analysis.
                    guid = new Guid(senseId.Substring(kAnalysisPrefix.Length));
                    IWfiAnalysis dbAnalysis = m_cache.ServiceLocator.GetInstance <IWfiAnalysisRepository>().GetObject(guid);
                    IWfiGloss dbGloss       = dbAnalysis.MeaningsOC.First();
                    dbGlosses = dbGloss.Form;
                }
                else
                {
                    guid = new Guid(senseId);
                    ILexSense dbSense = m_cache.ServiceLocator.GetInstance <ILexSenseRepository>().GetObject(guid);
                    dbGlosses         = dbSense.Gloss;
                }
                // Remove the gloss from the list of glosses for the sense
                int wsId = m_cache.WritingSystemFactory.GetWsFromStr(language);
                dbGlosses.set_String(wsId, (ITsString)null);

                // Delete the sense if there are no more glosses for it
                if (dbGlosses.StringCount == 0)
                {
                    RemoveSense(senseId, guid);
                }
            });
        }
Пример #29
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Determines if the specified lexeme type matches the specified morph type
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private static bool LexemeTypeAndMorphTypeMatch(LexemeType type, IMoMorphType morphType)
		{
			if (type == LexemeType.Word || type == LexemeType.Lemma)
				throw new ArgumentException("Morph type can never be of the specified lexeme type");

			switch (type)
			{
				case LexemeType.Prefix: return morphType.IsPrefixishType;
				case LexemeType.Suffix: return morphType.IsSuffixishType;
				case LexemeType.Stem: return morphType.IsStemType &&
					morphType.Guid != MoMorphTypeTags.kguidMorphPhrase &&
					morphType.Guid != MoMorphTypeTags.kguidMorphDiscontiguousPhrase;
				case LexemeType.Phrase:
					return morphType.Guid == MoMorphTypeTags.kguidMorphPhrase ||
						morphType.Guid == MoMorphTypeTags.kguidMorphDiscontiguousPhrase;
			}
			return false;
		}
Пример #30
0
		public TypeOfLexemeAttribute(LexemeType lexemeType)
		{
			_lexemeType = lexemeType;
		}
Пример #31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="LexicalEntry"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public LexicalEntry(LexemeType type, string form, int homograph)
		{
			Type = type;
			LexicalForm = form;
			Homograph = homograph;
			Senses = new List<LexSense>();
		}
Пример #32
0
 private void GenError(LexemeType got, LexemeType expecting, int line)
 {
     _errors.Add(string.Format("Syntax: On line: {2} expecting type: {0} got: {1}", expecting, got, line));
     throw new Exception(string.Format("Syntax: On line: {2} expecting type: {0} got: {1}", expecting, got, line));
 }
Пример #33
0
		public LexemeKey(LexemeType type, string lexicalForm) : this(type, lexicalForm, 1)
		{
		}
Пример #34
0
 public Lexeme(LexemeType type)
 {
     _type = type;
 }
Пример #35
0
        public SymbolObject LiteralPush(string value, LexemeType type)
        {
            SymbolObject obj = null;
            if (!Getliteral(value, out obj, type))
            {
                string datatype = "";
                switch(type)
                {
                    case LexemeType.Null:
                        datatype = "null";
                        break;
                    case LexemeType.True:
                    case LexemeType.False:
                        datatype = "bool";
                        break;
                    case LexemeType.Character:
                        datatype = "char";
                        break;
                    case LexemeType.Number:
                        datatype = "int";
                        break;

                }
                obj = new SymbolObject { Kind = KindType.Temp, Scope = "g", Value = value, SymId = "Ct" + _idCounter++, Data = new Data { AccessMode = "public", Type = datatype }, MemLocation = MemoryLocation.Global};
                _symbolTable.Add(obj.SymId, obj);
            }
            return obj;
        }
Пример #36
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a new LexicalEntry from the specified lexical entry in the DB
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private LexicalEntry CreateEntryFromDbEntry(LexemeType type, ILexEntry dbEntry)
		{
			if (type == LexemeType.Word)
				throw new ArgumentException("Lexeme type specified can not be created from a LexEntry");

			// A homograph number of zero in the DB means there is only one entry for the wordform.
			// However, the interface requires there be an entry with a homograph of one even if
			// there is only one entry.
			LexicalEntry entry = new LexicalEntry(type, dbEntry.HomographForm,
				dbEntry.HomographNumber > 0 ? dbEntry.HomographNumber : 1);

			// Add the senses to the interface (non-DB) entry
			foreach (ILexSense dbSense in dbEntry.SensesOS)
			{
				LexSense sense = new LexSense(dbSense.Guid.ToString());
				AddDbGlossesToSense(sense, dbSense.Gloss);
				entry.Senses.Add(sense); // Add the sense to the list of senses
			}
			return entry;
		}
 public Lexeme(LexemeType typeIn, String valueIn, int lineNoIn)
 {
     Init(typeIn, valueIn, lineNoIn);
 }
Пример #38
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Removes the gloss with the specified language form the sense with the specified information
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void RemoveGloss(LexemeType type, string lexicalForm, int homograph,
			string senseId, string language)
		{
			LexicalProviderManager.ResetLexicalProviderTimer();
			Logger.WriteEvent("Removing gloss from lexeme '" + lexicalForm + "' from an external application");

			NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
				{
					IMultiUnicode dbGlosses;
					Guid guid;
					if (senseId.StartsWith(kAnalysisPrefix))
					{
						// The "sense" is actually an analysis for a wordform and the gloss
						// we want to delete is a meaning for that analysis.
						guid = new Guid(senseId.Substring(kAnalysisPrefix.Length));
						IWfiAnalysis dbAnalysis = m_cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>().GetObject(guid);
						IWfiGloss dbGloss = dbAnalysis.MeaningsOC.First();
						dbGlosses = dbGloss.Form;
					}
					else
					{
						guid = new Guid(senseId);
						ILexSense dbSense = m_cache.ServiceLocator.GetInstance<ILexSenseRepository>().GetObject(guid);
						dbGlosses = dbSense.Gloss;
					}
					// Remove the gloss from the list of glosses for the sense
					int wsId = m_cache.WritingSystemFactory.GetWsFromStr(language);
					dbGlosses.set_String(wsId, (ITsString)null);

					// Delete the sense if there are no more glosses for it
					if (dbGlosses.StringCount == 0)
						RemoveSense(senseId, guid);
				});
		}
Пример #39
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds a new gloss to the sense with the specified information
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public LexGloss AddGlossToSense(LexemeType type, string lexicalForm, int homograph,
			string senseId, string language, string text)
		{
			LexicalProviderManager.ResetLexicalProviderTimer();
			Logger.WriteEvent("Adding new gloss to lexeme '" + lexicalForm + "' from an external application");

			return NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
				{
					IMultiUnicode dbGlosses;
					if (senseId.StartsWith(kAnalysisPrefix))
					{
						// The "sense" is actually an analysis for a wordform and our new
						// gloss is a new meaning for that analysis.
						Guid analysisGuid = new Guid(senseId.Substring(kAnalysisPrefix.Length));
						IWfiAnalysis dbAnalysis = m_cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>().GetObject(analysisGuid);
						IWfiGloss dbGloss = dbAnalysis.MeaningsOC.FirstOrDefault();
						if (dbGloss == null)
						{
							dbGloss = m_cache.ServiceLocator.GetInstance<IWfiGlossFactory>().Create();
							dbAnalysis.MeaningsOC.Add(dbGloss);
						}
						dbGlosses = dbGloss.Form;
						dbAnalysis.ApprovalStatusIcon = 1; // Assume the analysis from the external application is user approved
					}
					else
					{
						Guid senseGuid = new Guid(senseId);
						ILexSense dbSense = m_cache.ServiceLocator.GetInstance<ILexSenseRepository>().GetObject(senseGuid);
						dbGlosses = dbSense.Gloss;
					}

					// Add the new gloss to the list of glosses for the sense
					ILgWritingSystem writingSystem = m_cache.WritingSystemFactory.get_Engine(language);
					dbGlosses.set_String(writingSystem.Handle, TsStringUtils.MakeTss(text, writingSystem.Handle));

					return new LexGloss(language, text);
				});
		}
 public Lexeme(LexemeType typeIn, int lineNoIn)
 {
     Init(typeIn, null, lineNoIn);
 }
Пример #41
0
 public bool Getliteral(string value, out SymbolObject obj, LexemeType type)
 {
     string datatype = "";
     switch (type)
     {
         case LexemeType.Null:
             datatype = "null";
             break;
         case LexemeType.True:
         case LexemeType.False:
             datatype = "bool";
             break;
         case LexemeType.Character:
             datatype = "char";
             break;
         case LexemeType.Number:
             datatype = "int";
             break;
     }
     var result = _symbolTable.Values.FirstOrDefault(o => o.Value == value && o.Scope == "g" && o.Data.Type == datatype);
     if (result == null)
     {
         obj = null;
         return false;
     }
     obj = result;
     return true;
 }
Пример #42
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the morph type for the specified lexeme type.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private IMoMorphType GetMorphTypeForLexemeType(LexemeType type)
		{
			if (type == LexemeType.Word || type == LexemeType.Lemma)
				throw new ArgumentException("Morph type can never be of the specified lexeme type");

			IMoMorphTypeRepository repo = m_cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>();
			switch (type)
			{
				case LexemeType.Prefix: return repo.GetObject(MoMorphTypeTags.kguidMorphPrefix);
				case LexemeType.Suffix: return repo.GetObject(MoMorphTypeTags.kguidMorphSuffix);
				case LexemeType.Phrase: return repo.GetObject(MoMorphTypeTags.kguidMorphPhrase);
				case LexemeType.Stem: return repo.GetObject(MoMorphTypeTags.kguidMorphStem);
			}
			return null;
		}
Пример #43
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the DB LexEntry for the specified type and form (homograph currently ignored) or
		/// null if none could be found.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private ILexEntry GetDbLexeme(LexemeType type, string lexicalForm, int homograph)
		{
			if (type == LexemeType.Word)
				throw new ArgumentException("LexEntry can not be found for the Lexeme type specified");

			// ENHANCE: We may have to do something with the homograph number eventually, but
			// currently there is no correlation between the homograph number in the DB and
			// the homograph number passed from the external application.
			return m_cache.ServiceLocator.GetInstance<ILexEntryRepository>().GetHomographs(lexicalForm).FirstOrDefault(
				dbEntry => LexemeTypeAndMorphTypeMatch(type, dbEntry.PrimaryMorphType));
		}
 private void Init(LexemeType typeIn, String valueIn, int lineNoIn)
 {
     type = typeIn;
     value = valueIn;
     lineNumber = lineNoIn;
 }
Пример #45
0
 /// <summary>
 /// Предоставляет структуру, содержащую информацию о лексеме.
 /// </summary>
 /// <param name="name">Наименование</param>
 /// <param name="val">Значение</param>
 /// <param name="type">Тип</param>
 public Lexeme(string name, double val, LexemeType type)
 {
     Name  = name;
     Value = val;
     Type  = type;
 }
Пример #46
0
 public void AdvanceLexemeBuffer(LexemeType specifiedLexeme = LexemeType.Unspecified)
 {
     NextLexeme = _lexemeReader.GetNextLexemeFromBuffer(specifiedLexeme);
 }
Пример #47
0
 /// <summary>
 /// Предоставляет структуру, содержащую информацию о лексеме GCode-команды.
 /// </summary>
 /// <param name="name">Наименование команды</param>
 public Lexeme(string name)
 {
     Name  = name;
     Value = double.NaN;
     Type  = LexemeType.Command;
 }
Пример #48
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Looks up an lexeme
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public LexicalEntry GetLexeme(LexemeType type, string lexicalForm, int homograph)
		{
			LexicalProviderManager.ResetLexicalProviderTimer();

			switch (type)
			{
				case LexemeType.Word:
					IWfiWordform wf = GetDbWordform(lexicalForm);
					return (wf != null) ? CreateEntryFromDbWordform(wf) : null;
				default:
					ILexEntry dbEntry = GetDbLexeme(type, lexicalForm, homograph);
					return (dbEntry != null) ? CreateEntryFromDbEntry(type, dbEntry) : null;
			}
		}
Пример #49
0
 public void AddString(string str, LexemeType name)
 {
     AddStringInternal(str, name);
 }
Пример #50
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds a new sense to the lexeme with the specified information
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public LexSense AddSenseToEntry(LexemeType type, string lexicalForm, int homograph)
		{
			LexicalProviderManager.ResetLexicalProviderTimer();
			Logger.WriteEvent("Adding new sense to lexeme '" + lexicalForm + "' from an external application");

			return NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
				{
					string guid = string.Empty;
					switch (type)
					{
						case LexemeType.Word:
						{
							IWfiWordform dbWordform = GetDbWordform(lexicalForm);
							if (dbWordform == null)
								throw new ArgumentException("Entry in the lexicon not found for the specified information");

							// For wordforms, our "senses" could be new meanings of an analysis for the word
							// or it could be a brand new analysis. Because we have no idea what the user actually
							// wanted, we just assume the worst (they want to create a new analysis for the word
							// with a new meaning).
							IWfiAnalysis dbAnalysis = m_cache.ServiceLocator.GetInstance<IWfiAnalysisFactory>().Create();
							dbWordform.AnalysesOC.Add(dbAnalysis);
							guid = kAnalysisPrefix + dbAnalysis.Guid;
							break;
						}
						default:
						{
							ILexEntry dbEntry = GetDbLexeme(type, lexicalForm, homograph);
							if (dbEntry == null)
								throw new ArgumentException("Entry in the lexicon not found for the specified information");

							if (dbEntry.SensesOS.Count == 1 && dbEntry.SensesOS[0].Gloss.StringCount == 0)
							{
								// An empty sense exists (probably was created during a call to AddLexeme)
								guid = dbEntry.SensesOS[0].Guid.ToString();
								break;
							}

							ILexSense newSense = m_cache.ServiceLocator.GetInstance<ILexSenseFactory>().Create(
								dbEntry, new SandboxGenericMSA(), (ITsString) null);
							guid = newSense.Guid.ToString();
							break;
						}
					}
					return new LexSense(guid);
				});
		}
Пример #51
0
    public void GetLexeme_WhenCalledWithValidInput_ShouldIgnoreCommentsAndWhiteSpace(string line, LexemeType expectedType, object expectedValue)
    {
        var sut    = CreateSut(line);
        var lexeme = sut.GetLexeme();

        lexeme.Type.Should().Be(expectedType);
        lexeme.Value.Should().BeEquivalentTo(expectedValue);
    }
        private bool accept(LexemeType typeIn)
        {
            if (currentLexeme.Type == typeIn)
            {
                if (inRule)
                    rulesLexemes.Add(currentLexeme);

                GetNext();
                return true;
            }

            //int errLineNo = currentLexeme.LineNumber;
            string errMsg = "Expected " + typeIn + " found " + currentLexeme + " on line " + currentLexeme.LineNumber
                            + "\nLine: " + lexA.GetLine(currentLexeme.LineNumber);

            throw new Exception(errMsg);
        }