private void InitializeFromText(string fullText) { fullText = fullText.Replace("\\n", "\n"); //If double backslashes are present convert to single var lines = fullText.Split('\n').ToList(); //Break text into list of lines lines.ForEach(s => s.Trim()); //Trim whitespace from each line //Identify phones,mail and website with simple regex and remove from full text after identification Email = lines.Where(l => _matchMail.IsMatch(l)).FirstOrDefault(); lines.Remove(Email); Mobile = lines.Where(l => _matchMobilePhone.IsMatch(l)).FirstOrDefault(); if (Mobile != null) { Mobile = Mobile.Trim().Replace(" ", ""); //remove whitespaces to compensate for D365 20 char limit } lines.Remove(Mobile); FixedLine = lines.Where(l => _matchLandlinePhone.IsMatch(l)).FirstOrDefault(); if (FixedLine != null) { FixedLine = FixedLine.Trim().Replace(" ", ""); } lines.Remove(FixedLine);//remove whitespaces to compensate for D365 20 char limit Website = lines.Where(l => _matchWebSite.IsMatch(l)).FirstOrDefault(); lines.Remove(Website); // Try to identify organistation name "the easy way" by looking for an official legal incorporation abbreviation foreach (var form in _incorporationForms) { if (lines.Exists(l => l.Contains(form))) { Organisation = lines.Where(l => l.Contains(form)).FirstOrDefault(); lines.Remove(Organisation); } } //The rest of the text should contain names, address and organisation //To identify names, organisation (if not identified by incorporation abbreviation) and address use AzureML and entity extraction on remaining full text //TODO: We should find a way to join all address lines (City,Street,..) before sending to ML var extractor = new EntityExtractor(lines); //if an organisation match has not been found - try named entity recognition if (Organisation == "") { Organisation = extractor.OutputData.Where(data => data.Type == "ORG").FirstOrDefault() != null? extractor.OutputData.Where(data => data.Type == "ORG").FirstOrDefault().Mention : ""; } FullName = extractor.OutputData.Where(data => data.Type == "PER").FirstOrDefault() != null? extractor.OutputData.Where(data => data.Type == "PER").FirstOrDefault().Mention : ""; Address = extractor.OutputData.Count(data => data.Type == "LOC") > 0 ? string.Join("\n", extractor.OutputData.Where(data => data.Type == "LOC").Select(s => s.Mention)) : ""; System.Console.WriteLine(""); }
private async void saveButton_Click(object sender, RoutedEventArgs e) { val = new Validation(); if (val.isEmpty(firstName) || val.isEmpty(lastName) || val.isEmpty(addressLine1) || val.isEmpty(addressLine2) || val.isEmpty(addressLine3) || val.isEmpty(email) || val.isEmpty(mobileNumber.ToString()) || val.isEmpty(FixedLine.ToString())) { await this.ShowMessageAsync("Error", "Input Data Cannot Be Empty", MessageDialogStyle.Affirmative); } else if (val.isNumeric(mobileNumber.ToString()) || val.isNumeric(FixedLine.ToString())) { await this.ShowMessageAsync("Error", "Contact Numbers Should Be Numeric", MessageDialogStyle.Affirmative); } else { int affectedLines = 0; customerData = new CustomerData(); customerData.setFirstName(firstName); customerData.setLastName(lastName); customerData.setAddress(addressLine1, addressLine2, addressLine3); customerData.setEmail(email); customerData.setMobileNumer(mobileNumber); customerData.setFixedNumber(fixedNumber); try { handleDatabase = new HandleDatabase(); affectedLines = handleDatabase.executeCustomerEntry(customerData); if (affectedLines > 0) { await this.ShowMessageAsync("Successfull", "Customer have been Successfully Entered", MessageDialogStyle.Affirmative); FirstName.Text = ""; LastName.Text = ""; Address1.Text = ""; Address2.Text = ""; Address3.Text = ""; Email.Text = ""; FixedLine.Text = ""; Mobile.Text = ""; } else { await this.ShowMessageAsync("Error", "Sorry Can not Create the Profile, Please Try again", MessageDialogStyle.Affirmative); } } catch (SqlException sqlException) { Console.WriteLine(sqlException); } } }
void computeNewFixedVelocity() { _fixedLines.Clear(); for (var i = 0; i < neighborsList.Count; ++i) { var neighbor = neighborsList[i]; var relativePos = neighbor.Position.ToVector2d() - _self.Position.ToVector2d(); var mRelativePos = relativePos.Magnitude(); //flag var relativeVel = _self.Velocity.ToVector2d() - neighbor.Velocity.ToVector2d(); var comRadius = neighbor.Radius + _self.Radius; FixedLine line = new FixedLine(); Vector2d u = Vector2d.zero; if (comRadius < mRelativePos) { Vector2d vec = relativeVel - relativePos / FixedMath.Create(6); var mVec = vec.Magnitude(); var dotProduct = Vector2d.Dot(vec, relativePos); if (dotProduct < 0 && dotProduct.Mul(dotProduct) > comRadius.Mul(comRadius) * mVec.Mul(mVec)) { Vector2d normVec = vec.Normalize(); line.direction = new Vector2d(normVec.y, -normVec.x); u = normVec * (comRadius.Div(FixedMath.Create(6)) - mVec); } else { long mEdge = FixedMath.Sqrt(mRelativePos.Mul(mRelativePos) - comRadius.Mul(comRadius)); Vector2d edge = Vector2d.zero; if (Vector2d.det(relativePos, vec) > 0) { edge = Vector2d.rotate(relativePos, mEdge.Div(mRelativePos), comRadius.Div(mRelativePos)); } else { edge = Vector2d.rotate(relativePos, mEdge.Div(mRelativePos), -comRadius.Div(mRelativePos)); edge *= -1; } line.direction = edge.Normalize(); // project u' = v * dot(u, v) / v^2 // v = ||line.direction|| = 1 u = Vector2d.Dot(relativeVel, line.direction) * line.direction - relativeVel; } } // tricks else { Vector2d vec = relativeVel - relativePos / LockFrameMgr.FixedFrameTime; Vector2d normVec = vec.Normalize(); line.direction = new Vector2d(normVec.y, -normVec.x); u = (comRadius.Div(LockFrameMgr.FixedFrameTime) - vec.Magnitude()) * normVec; } line.point = _fixedVecocity + u / 2; _fixedLines.Add(line); } _fixedVecocity = linearPrograming(_fixedLines); }