public SentenceGrammarRule(GrammaticalType fragment, short modificationOrder, bool subjectPredicate, SentenceType type) { SubjectPredicate = subjectPredicate; ModificationOrder = modificationOrder; Fragment = fragment; Type = type; }
public static string GetPunctuationMark(SentenceType type, bool upsideDown = false) { string punctuation = string.Empty; switch (type) { case SentenceType.Exclamation: punctuation = upsideDown ? "!" : "!"; break; case SentenceType.ExclamitoryQuestion: punctuation = upsideDown ? "?!" : "?!"; break; case SentenceType.Partial: punctuation = ";"; break; case SentenceType.Question: punctuation = upsideDown ? "?" : "?"; break; case SentenceType.Statement: case SentenceType.None: punctuation = "."; break; } return(punctuation); }
public double GetScore(SentenceType target, SentenceType existing) { if (target == existing) { return(1.0); } if (target == SentenceType.Unidentifiable || existing == SentenceType.Unidentifiable) { return(0.25); } if (target == SentenceType.Interrogative) { return(0.0); } if (target == SentenceType.Imperative) { return(0.0); } if (target == SentenceType.Declarative && existing == SentenceType.Exclamatory) { return(.75); } if (target == SentenceType.Exclamatory && existing == SentenceType.Declarative) { return(.75); } return(0.0); }
public SentenceGrammarRule() { SubjectPredicate = false; ModificationOrder = 0; Fragment = GrammaticalType.None; Type = SentenceType.None; }
public SourceWithTranslation GetOrCreate(SentenceType type, PronunciationForUser source, PronunciationForUser translation, byte[] image, int?rating = null) { //TODO: проверять корректность параметров SourceWithTranslation result = null; Adapter.ActionByContext(context => { SentenceTranslation sentenceTranslation = GetSentenceTranslation(context, source, translation); if (sentenceTranslation != null) { //обновить возможно изменившиеся поля SetSentenceTranslation(sentenceTranslation, type, image, rating); context.SaveChanges(); if (IdValidator.IsValid(sentenceTranslation.Id)) { result = new SourceWithTranslation(); result.Set(sentenceTranslation.Id, source, translation); } } else { result = CreateSentencencesWithTranslation(type, source, translation, image, rating); } }); return(result); }
internal string GetEntityName(SentenceType sentenceType) { if (string.IsNullOrEmpty(interpolator.Entity.MappTo)) { return(interpolator.Entity.Name); } else { string entityName = string.Empty; if (!string.IsNullOrEmpty(_extender.MainTableName)) { entityName = _extender.MainTableName; } else { entityName = interpolator.Entity.MappTo; } string join = string.Empty; if (_extender.GetJoin().ContainsKey(sentenceType)) { join = _extender.GetJoin()[sentenceType]; } return(string.Format("{0} {1}", entityName, join).TrimEnd(new char[] { ' ' })); } }
/// <summary> /// Creates a negation Sentence. /// </summary> /// <param name="ty">The type of Sentence to create.</param> /// <param name="l">The sentence to negate with this Sentence.</param> public Sentence(SentenceType ty, Sentence l) { this.type = ty; this.left = l; this.right = null; this.atom = '\0'; }
/// <summary> /// Creates an atomic Sentence. /// </summary> /// <param name="ty">The type of Sentence to create.</param> /// <param name="a">The atom to represent with this Sentence.</param> public Sentence(SentenceType ty, char a) { this.type = ty; this.left = null; this.right = null; this.atom = a; }
/// <summary> /// Creates an empty Sentence. /// </summary> public Sentence() { this.type = SentenceType.OTHER; this.left = null; this.right = null; this.atom = '\0'; }
private SourceWithTranslation CreateSentencencesWithTranslation(SentenceType type, PronunciationForUser source, PronunciationForUser translation, byte[] image = null, int?rating = null) { SourceWithTranslation result = null; Adapter.ActionByContext(context => { Sentence sourceSentence = GetOrAddSentenceToContext(source.LanguageId, source.Text, context); Sentence translationSentence = GetOrAddSentenceToContext(translation.LanguageId, translation.Text, context); context.SaveChanges(); if (IdValidator.IsInvalid(sourceSentence.Id) || IdValidator.IsInvalid(translationSentence.Id)) { return; } var sentenceTranslation = new SentenceTranslation { SentenceId1 = sourceSentence.Id, SentenceId2 = translationSentence.Id }; SetSentenceTranslation(sentenceTranslation, type, image, rating); context.SentenceTranslation.Add(sentenceTranslation); context.SaveChanges(); if (IdValidator.IsInvalid(sentenceTranslation.Id)) { return; } result = ConverterEntities.ConvertToSourceWithTranslation(sentenceTranslation.Id, sentenceTranslation.Image, source.LanguageId, sourceSentence, translationSentence); }); return(result); }
private static ulong CalculateSum(string text, string word, int wordPosition, SentenceType sentenceType) { if (string.IsNullOrWhiteSpace(text)) { throw new ArgumentException("The text parameter cannot be null or empty"); } if (string.IsNullOrWhiteSpace(word)) { throw new ArgumentException("The word parameter cannot be null or empty"); } var sum = 0UL; if (sentenceType == SentenceType.Question) { for (var i = wordPosition + word.Length; i < signPosition; i++) { if (text[i] == SPACE_SYMBOL) { continue; } sum += char.ToUpper(text[i]); } } else if (sentenceType == SentenceType.Statement) { int currentPos = wordPosition - 1; int beginPos; while (true) { if (char.IsUpper(text[currentPos])) { beginPos = currentPos; break; } currentPos--; } for (var i = beginPos; i < wordPosition; i++) { if (text[i] == SPACE_SYMBOL) { continue; } sum += char.ToUpper(text[i]); } } else { throw new InvalidOperationException("Cannot calculate sum for a missing sentence type"); } return(sum); }
private static void SetSentenceTranslation(SentenceTranslation sentenceTranslation, SentenceType type, byte[] image, int?rating) { sentenceTranslation.Image = image; sentenceTranslation.Rating = rating; sentenceTranslation.Type |= (int)type; }
private void ReleaseSentence(SentenceType sentence) { sentence.vertexBuffer?.Dispose(); sentence.vertexBuffer = null; sentence.indexBuffer?.Dispose(); sentence.indexBuffer = null; return; }
private bool InitializeSentence(SharpDX.Direct3D11.Device device, int maxLength) { try { sentence_ = new SentenceType { maxLength = maxLength, vertexCount = 6 * maxLength, indexCount = 6 * maxLength }; VertexType[] vertices = new VertexType[sentence_.vertexCount]; uint[] indices = new uint[sentence_.indexCount]; for (int i = 0; i < sentence_.indexCount; ++i) { indices[i] = (uint)i; } var vertexBufferDesc = new BufferDescription() { Usage = ResourceUsage.Dynamic, SizeInBytes = Utilities.SizeOf <VertexType>() * sentence_.vertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }; sentence_.vertexBuffer = SharpDX.Direct3D11.Buffer.Create(device, vertices, vertexBufferDesc); var indexBufferDesc = new BufferDescription() { Usage = ResourceUsage.Default, SizeInBytes = Utilities.SizeOf <uint>() * sentence_.indexCount, BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }; sentence_.indexBuffer = SharpDX.Direct3D11.Buffer.Create(device, indices, indexBufferDesc); vertices = null; indices = null; return(true); } catch (ArgumentException e) { MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK); return(false); } }
public IEnumerable <IWord> FindWordsFromSentence(int lengthWord, SentenceType sentenceType) { var result = new List <IWord>(); var sentences = Sentences.Where(s => s.SentenceType == sentenceType).ToList(); foreach (var sentence in sentences) { result.AddRange(sentence.GetWordsWithoutRepetition(lengthWord)); } return(result.GroupBy(x => x.Chars.ToLower()).Select(x => x.First()).ToList()); }
private int WriteShuffledSentencesToResult(KnowledgeDataType dataType, SentenceType sentenceType, int count, List <GeneratedKnowledgeItem> result) { List <long> ids = Adapter.ExecuteStoredProcedure("get_shuffle_sentences", fields => (long)fields[0], _userId, (int)dataType, (int)sentenceType, _mainLanguageId, _translationLanguageId, count); WriteDataToResult(dataType, result, ids); return(ids != null ? ids.Count : 0); }
public static Text FindAllSentenceType(Text text, SentenceType type) { Text resultSentences = new Text(); foreach (var sentence in text.Value) { if (sentence.Type == type) { resultSentences.Value.Add(sentence); } } return(resultSentences); }
bool RenderSentence(DeviceContext deviceContext, SentenceType sentence, Matrix world, Matrix orthogonal) { deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(sentence.VertexBuffer, Utilities.SizeOf <VertexType>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(sentence.IndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; var pixelColor = new Color4(sentence.Red, sentence.Green, sentence.Blue, 1.0f); if (!fontShader.Render(deviceContext, sentence.IndexCount, world, baseViewMatrix, orthogonal, font.ObjectTexture, pixelColor)) { return(false); } return(true); }
public WordRule() { AltersSentence = SentenceType.None; NeedsArticle = false; WhenPlural = false; WhenPossessive = false; SpecificAddition = null; SpecificWord = null; Tense = LexicalTense.None; Perspective = NarrativePerspective.None; FromType = LexicalType.None; FromRole = GrammaticalType.None; FromSemantics = string.Empty; FromBeginsWith = string.Empty; FromEndsWith = string.Empty; }
private void SetType(List <Character> characters) { var ch = characters.Find(character => elementsSentenceType.Contains(character.Value)); switch (ch.Value) { case '.': Type = SentenceType.Declarative; break; case '!': Type = SentenceType.Exclamatory; break; case '?': Type = SentenceType.Interrogative; break; } }
bool InitializeSentence(out SentenceType sentence, int maxLength, Device device) { sentence = new SentenceType() { MaxLength = maxLength, VertexCount = maxLength * 6 }; sentence.IndexCount = sentence.VertexCount; try { var vertices = new VertexType[sentence.VertexCount]; var indices = new int[sentence.IndexCount]; for (int i = 0; i < sentence.IndexCount; i++) { indices[i] = i; } var vertexBufferDescription = new BufferDescription { Usage = ResourceUsage.Default, SizeInBytes = Utilities.SizeOf <VertexType>() * sentence.VertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }; sentence.VertexBuffer = Buffer.Create(device, vertices, vertexBufferDescription); var indexBufferDescription = new BufferDescription { Usage = ResourceUsage.Default, SizeInBytes = Utilities.SizeOf <int>() * sentence.IndexCount, BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }; sentence.IndexBuffer = Buffer.Create(device, indices, indexBufferDescription); } catch { return(false); } return(true); }
public Sentence(XElement item) { iD = item.Attribute("ID").Value.ToInt(); type = (SentenceType)Enum.Parse(typeof(SentenceType), item.Attribute("SentenceType").Value); speakerID = item.Attribute("SpeakerID").Value.ToInt(); var _attribute = item.Attribute("SubID"); if (_attribute != null) { subID = _attribute.Value.ToInt(); } var collection = item.Elements("Effect"); foreach (var eff in collection) { iEffect tar = new Effect(eff); effList.Add(tar); } }
bool UpdateSentence(ref SentenceType sentence, string text, int positionX, int positionY, float red, float green, float blue, DeviceContext deviceContext) { try { sentence.Red = red; sentence.Green = green; sentence.Blue = blue; if (text.Length > sentence.MaxLength) { return(false); } var vertices = new VertexType[sentence.VertexCount]; var drawX = (float)-screenWidth / 2 + positionX; var drawY = (float)screenHeight / 2 - positionY; font.BuildVertexArray(vertices, text, drawX, drawY); deviceContext.UpdateSubresource(vertices, sentence.VertexBuffer); } catch { return(false); } return(true); }
public List <SourceWithTranslation> GetByCount(UserLanguages userLanguages, SentenceType type, int count) { long sourceLanguageId = userLanguages.From.Id; long translationLanguageId = userLanguages.To.Id; var convertedType = (int)type; List <SourceWithTranslation> result = Adapter.ReadByContext(c => { var joinedSequence = (from s1 in c.Sentence join st in c.SentenceTranslation on s1.Id equals st.SentenceId1 join s2 in c.Sentence on st.SentenceId2 equals s2.Id where (st.Type & convertedType) == convertedType && ((s1.LanguageId == sourceLanguageId && s2.LanguageId == translationLanguageId) || (s1.LanguageId == translationLanguageId && s2.LanguageId == sourceLanguageId)) select new { st.Id, st.Image, s1, s2 }).Take(count); return (joinedSequence.AsEnumerable().Select( e => ConverterEntities.ConvertToSourceWithTranslation(e.Id, e.Image, sourceLanguageId, e.s1, e.s2)). ToList()); }); return(result); }
public void SetSentenceType(SentenceType type) { Type = type; }
/// <summary> /// Convert sentence type to string used in script file. /// </summary> /// <param name="type">Sentence type.</param> /// <returns>String representation of sentence type.</returns> public static string SentenceTypeToString(SentenceType type) { string name = string.Empty; switch (type) { case SentenceType.Declarative: name = @"declarative"; break; case SentenceType.YesNoQuestion: name = @"ynq"; break; case SentenceType.WhoQuestion: name = @"whq"; break; case SentenceType.Exclamatory: name = @"exclam"; break; case SentenceType.Imperative: name = @"imperative"; break; case SentenceType.Hailing: name = @"hail"; break; case SentenceType.SingleWordQuestion: name = @"swq"; break; case SentenceType.ChoiceQuestion: name = @"choiceques"; break; case SentenceType.Cuteness: name = @"cuteness"; break; } return name; }
public Token GetSubject(List <OpenieTriple> openieTriples, List <Token> tokens, SentenceType sentenceType) { Token subject; if (openieTriples.Count > 0) { subject = tokens.FirstOrDefault(t => t.Word == openieTriples.First().Subject); if (subject != null) { return(subject); } } subject = tokens.FirstOrDefault(t => t.IncomingDependencyLabel != null && (t.IncomingDependencyLabel.StartsWith("nsubj") || t.IncomingDependencyLabel.StartsWith("csubj"))); if (subject != null) { return(subject); } if (sentenceType == SentenceType.Imperative) { return(new Token { Word = "you", Lemmas = "you" }); } return(new Token()); }
public IEnumerable <IWord> GetWordsFromSentences(IText text, SentenceType sentenceType, int wordLength) { return(SelectSentences(text, x => x.SentenceTypes.Contains(sentenceType)) .SelectMany(y => SelectElements <IWord>(y, z => z.Length == wordLength)).Distinct()); }
public SentenceWrapper(string sentence, Transform position, SentenceType type) { Sentence = sentence; Position = position; Type = type; }
public Token GetObject(List <OpenieTriple> openieTriples, List <Token> tokens, SentenceType sentenceType) { Token sentenceObject; if (openieTriples.Count > 0) { sentenceObject = tokens.FirstOrDefault(t => t.Word == openieTriples.First().Object); if (sentenceObject != null) { return(sentenceObject); } } sentenceObject = tokens.FirstOrDefault(t => t.IncomingDependencyLabel != null && t.IncomingDependencyLabel.StartsWith("dobj")); if (sentenceObject != null) { return(sentenceObject); } sentenceObject = tokens.LastOrDefault(t => t.IncomingDependencyLabel != null && t.IncomingDependencyLabel == "root" && t.PosTag.StartsWith("NN")); if (sentenceObject != null) { return(sentenceObject); } return(new Token()); }
/// <summary> /// 解析整条语句,生成树型结构 /// </summary> public void Parse() { string s = string.Empty; Char[] charArray = sentence.ToCharArray(); for (int i = 0; i < charArray.Length; i++) { char c=charArray[i]; if (c == '\'') //如果碰见一个“'”,调用ParseInQuotation记录从该处开始其后的字符串 { if (s != string.Empty) { throw new Exception("“'”附近有语法错误"); } ParseInQuotation(ref charArray, ref i); } else if (c == '(') //如果碰见一个“(”,调用ParseInBracket记录从该处开始到与之对应的“)”之间的内容 { string funName = string.Empty; if (s != string.Empty) { SyntaxNode node = new SyntaxNode(); node.ParentNode = this; node.sentence = s; node.SentenceType = SentenceType.Function; this.nodes.Add(node); funName = s.ToLower(); s = string.Empty; } ParseInBracket(ref charArray, ref i); if (funKeywords.Contains(funName) && this.nodes[this.nodes.Count - 1].nodes.Count > 0) this.nodes[this.nodes.Count - 1].nodes[0].SentenceType = SentenceType.Keyword; } else if (c == ' ') //如果碰见一个空格,记录空格前的内容 { if (s != string.Empty) { SyntaxNode node = new SyntaxNode(); node.ParentNode = this; if (nodes.Count > 0 && nodes[nodes.Count - 1].sentenceType == SentenceType.From) { node.sentenceType = SentenceType.Entity; EntityInfo entityInfo = EntityMap.GetEntityInfo(GetName(s)); if (entityInfo == null) throw new Exception("from后有语法错误,使用了一个不存在的实体名"); this.map = entityInfo.PropertyMap; } else node.SentenceType = GetSentenceType(s); node.sentence = GetName(s) + " "; this.nodes.Add(node); s = string.Empty; } } else if (c == '+' || c == '-' || c == '*' || c == '/' || c == '=' || c == '!' || c == '<' || c == '>' || c == ',')//如果碰见一个符号,记录符号前的内容及符号本身 { if (s != string.Empty) { SyntaxNode node = new SyntaxNode(); node.ParentNode = this; node.SentenceType = GetSentenceType(s); node.sentence = s; this.nodes.Add(node); } SyntaxNode operatorNode = new SyntaxNode(); operatorNode.ParentNode = this; operatorNode.SentenceType = SentenceType.Symbol; operatorNode.sentence = c.ToString(); this.nodes.Add(operatorNode); s = string.Empty; } else { s += c.ToString(); } } //记录最后的内容 if (s != string.Empty) { SyntaxNode node = new SyntaxNode(); node.parentNode = this; if (nodes.Count > 0 && nodes[nodes.Count - 1].sentenceType == SentenceType.From) { node.sentenceType = SentenceType.Entity; EntityInfo entityInfo = EntityMap.GetEntityInfo(GetName(s)); if (entityInfo == null) throw new Exception("from后有语法错误,使用了一个不存在的实体名"); this.map = entityInfo.PropertyMap; } else node.SentenceType = GetSentenceType(s); node.sentence = GetName(s); this.nodes.Add(node); } }
public SentenceType Parse(string sentence) { SentenceType type = SentenceType.None; // Discard the sentence if its checksum does not match our calculated checksum if (!Validate || IsValidSentence(sentence)) { bool result; // Look at the first word to decide where to go next switch (GetWords(sentence)[0]) { case "$GPRMC": // A "Recommended Minimum" sentence was found! result = ParseGprmc(sentence); if (result) { type = SentenceType.Gprmc; } break; case "$GPGSV": // A "Satellites in View" sentence was received result = ParseGpgsv(sentence); if (result) { type = SentenceType.Gpgsv; } break; case "$GPGSA": result = ParseGPGSA(sentence); if (result) { type = SentenceType.Gpgsa; } break; // Fix Data case "$GPGGA": result = ParseGpgga(sentence); if (result) { type = SentenceType.Gpgga; } break; case "$GPVTG": result = ParseGpvtg(sentence); if (result) { type = SentenceType.Gpvtg; } break; default: // Indicate that the sentence was not recognized break; } } return(type); }