Exemplo n.º 1
0
        public void TestUriRef()
        {
            IDictionary <String, String> prefixMap = QueryUtils.ParsePrefixes(PREFIXES);

            WhereClause where = QueryUtils.ParseWhere(
                "qm:testCase=<http://example.org/tests/24>", prefixMap);

            IList <SimpleTerm> children = where.Children;

            Assert.AreEqual(1, children.Count, "Where clause should only have one term");

            SimpleTerm simpleTerm = children[0];
            PName      prop       = simpleTerm.Property;

            Assert.AreEqual(prop.ns + prop.local, "http://qm.example.com/ns/testCase");
            Assert.IsTrue(simpleTerm is ComparisonTerm);

            ComparisonTerm comparison = (ComparisonTerm)simpleTerm;

            Assert.AreEqual(comparison.Operator, Operator.EQUALS);

            IValue v = comparison.Operand;

            Assert.IsTrue(v is IUriRefValue);

            IUriRefValue uriRef = (IUriRefValue)v;

            Assert.AreEqual("http://example.org/tests/24", uriRef.Value);
        }
Exemplo n.º 2
0
        private void FillMatrixByWord(SimpleTerm term, int i)
        {
            List <int> indexesOfLetters = new List <int>();

            for (int ind = 0; ind < term.Word.Length; ind++)
            {
                if (char.ToLower(term.Word[ind]) == char.ToLower(_mainWord.Word[i - 1]))
                {
                    indexesOfLetters.Add(ind);
                }
            }

            int index = -1;

            if (indexesOfLetters.Count > 0)
            {
                index = indexesOfLetters[GetRandom(indexesOfLetters.Count)];
            }

            if (index >= 0)
            {
                int length = term.Word.Length;
                for (int k = 0; k < length; k++)
                {
                    _preparingMatrix[i - 1, k + MainWordHorizontalIndex - index] = new LetterFromWord(term.Word[k], term);
                }
            }
        }
Exemplo n.º 3
0
 public MainWindow(Serializer ser)
 {
     Serializer = ser;
     Serializer.DeleteSimilarTerms();
     Serializer.SortList();
     InitializeComponent();
     _editedTerm = new SimpleTerm("", "");
 }
Exemplo n.º 4
0
 private bool SomeDescriptionWordIsKey(SimpleTerm term)
 {
     foreach (var word in term.DescriptionWordsAndSplittersList)
     {
         if (word.IsKeyWord)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 5
0
        public override void VisitMatchingTerms(IndexReader reader, string fieldName, SimpleTerm.IMatchingTermVisitor mtv)
        {
            int prefixLength = prefix.Length;
            Terms terms = MultiFields.GetTerms(reader, fieldName);
            if (terms != null)
            {
                TermsEnum termsEnum = terms.Iterator(null);

                TermsEnum.SeekStatus status = termsEnum.SeekCeil(prefixRef);
                BytesRef text;
                if (status == TermsEnum.SeekStatus.FOUND)
                {
                    text = prefixRef;
                }
                else if (status == TermsEnum.SeekStatus.NOT_FOUND)
                {
                    text = termsEnum.Term();
                }
                else
                {
                    text = null;
                }

                while (text != null)
                {
                    if (text != null && StringHelper.StartsWith(text, prefixRef))
                    {
                        string textString = text.Utf8ToString();
                        Match matcher = pattern.Match(textString.Substring(prefixLength));
                        if (matcher.Success)
                        {
                            mtv.VisitMatchingTerm(new Term(fieldName, textString));
                        }
                    }
                    else
                    {
                        break;
                    }
                    text = termsEnum.Next();
                }
            }
        }
Exemplo n.º 6
0
        private void ChooseRandomMainWord()
        {
            int min, max;

            min = (from t in List orderby t.Word.Length select t).ToList().First().Word.Length;
            max = (from t in List orderby t.Word.Length select t).ToList().Last().Word.Length;
            int dif = (max - min) / 3;

            if (_lvl == 1)
            {
                max = min + dif;
            }
            else if (_lvl == 2)
            {
                min = min + dif;
                max = max - dif;
            }
            else
            {
                min = max - dif;
            }

            List <SimpleTerm> mainWordCandidates = (from t in List where (t.Word.Length >= min) && (t.Word.Length <= max) orderby t.Word.Length select t).ToList();

            while (mainWordCandidates.Count == 0)
            {
                min--;
                max++;
                mainWordCandidates = (from t in List where (t.Word.Length >= min) && (t.Word.Length <= max) orderby t.Word.Length select t).ToList();
            }
            if (mainWordCandidates.Count > 0)
            {
                _maxLength = (from t in List orderby t.Word.Length select t).ToList().Last().Word.Length;
                _mainWord  = mainWordCandidates[GetRandom(mainWordCandidates.Count)];
                List.Remove(_mainWord);
            }
        }
Exemplo n.º 7
0
        private void EditBTN_Click(object sender, RoutedEventArgs e)
        {
            bool editingSuccess = false;

            if ((!(string.IsNullOrEmpty(TermTB.Text) || string.IsNullOrEmpty(DescriptionTB.Text))))
            {
                if (!_editMode)
                {
                    try
                    {
                        Serializer.TermList.Add(new SimpleTerm(TermTB.Text, DescriptionTB.Text));
                        if (Serializer.DeleteSimilarTerms())
                        {
                            MessageBox.Show("Данный термин уже внесён в словарь!");
                        }
                        else
                        {
                            editingSuccess = true;
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Не удалось добавить новый термин.");
                    }
                }
                else
                {
                    var termEdited = new SimpleTerm(TermTB.Text, DescriptionTB.Text);
                    var hasSimilar = (from t in Serializer.TermList where t.Word == termEdited.Word && t.Description == termEdited.Description select t).Count();
                    if (hasSimilar != 0)
                    {
                        MessageBox.Show("Данный термин уже внесён в словарь!");
                    }
                    else
                    {
                        _editedTerm.Word        = termEdited.Word;
                        _editedTerm.Description = termEdited.Description;
                        editingSuccess          = true;
                    }
                }
            }
            else
            {
                MessageBox.Show("Нужно заполнить поля термин и описание перед добавлением.");
            }
            if (editingSuccess)
            {
                Serializer.SortList();
                Serializer.Serialize();
                EditBTN.FontFamily = new FontFamily("Segoe MDL2 Assets");
                EditBTN.Foreground = Brushes.MediumSeaGreen;
                EditBTN.FontWeight = FontWeights.Bold;
                EditBTN.Content    = "\xE73E" + " ";
                EditBTN.IsEnabled  = false;
            }
            else
            {
                EditBTN.FontFamily = new FontFamily("Segoe MDL2 Assets");
                EditBTN.Foreground = Brushes.Red;
                EditBTN.FontWeight = FontWeights.Bold;
                EditBTN.Content    = "\xE711" + " ";
                EditBTN.IsEnabled  = false;
            }
        }
Exemplo n.º 8
0
 private static void DisableCheckBox(CheckBox isKey, SimpleTerm term)
 {
     isKey.IsChecked       = false;
     isKey.IsEnabled       = false;
     term.ReadyForFillGame = false;
 }
Exemplo n.º 9
0
 public LetterFromWord(char letter, SimpleTerm term)
 {
     Letter = letter;
     Term   = term;
 }
Exemplo n.º 10
0
 public SimpleLambda(string parameter, SimpleTerm body)
 {
     Parameter = parameter;
     Body      = body;
 }
Exemplo n.º 11
0
 public SimplePair(SimpleTerm left, SimpleTerm right)
 {
     Left  = left;
     Right = right;
 }
Exemplo n.º 12
0
 public SimpleType(Polarity polarity, SimpleTerm quantifier, SimpleTerm body)
 {
     Polarity   = polarity;
     Quantifier = quantifier;
     Body       = body;
 }
Exemplo n.º 13
0
 public SimpleUnpack(string left, string right, SimpleTerm continuation)
 {
     Left         = left;
     Right        = right;
     Continuation = continuation;
 }
Exemplo n.º 14
0
 public SimpleApply(SimpleTerm argument)
 {
     Argument = argument;
 }