public void textToWords(Document doc, IndexRoot indexRoot, string docTextString, Placement documentPlacement, Placement documentTextPlacement, Placement wordPlacement, Placement wordHitPlacement) { DocumentText docText = new DocumentText(docTextString, doc); Word word; doc.Persist(documentPlacement, session); doc.Page.Database.Name = doc.Name; docText.Persist(documentTextPlacement, session); indexRoot.repository.documentSet.Add(doc); doc.Content = docText; docTextString = docTextString.ToLower(); string[] excludedWords = new string[] { "and", "the" }; char[] splitChars = new char[] { ' ', '\n', '(', '"', '!', ',', '(', ')', '\t' }; string[] words = docTextString.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); UInt64 wordCt = 0; int i = 0; string aWord; char[] trimEndChars = new char[] { ';', '.', '"', ',', '\r', ':', ']', '!', '?', '+', '(', ')', '\'', '{', '}', '-', '`', '/', '=' }; char[] trimStartChars = new char[] { ';', '&', '-', '#', '*', '[', '.', '"', ',', '\r', ')', '(', '\'', '{', '}', '-', '`' }; foreach (string wordStr in words) { i++; aWord = wordStr.TrimEnd(trimEndChars); aWord = aWord.TrimStart(trimStartChars); word = new Word(aWord); if (aWord.Length > 1 && excludedWords.Contains(aWord) == false) { createLocalInvertedIndex(doc, word, wordCt, wordPlacement, wordHitPlacement); ++wordCt; } } }
public void textToWords(Document doc, IndexRoot indexRoot, string docTextString) { DocumentText docText = new DocumentText(docTextString, doc); session.Persist(doc); doc.Page.Database.Name = doc.Name; session.Persist(docText); indexRoot.Repository.DocumentSet.Add(doc); doc.Content = docText; docTextString = docTextString.ToLower(); string[] excludedWords = new string[] { "and", "the" }; char[] splitChars = new char[] { ' ', '\n', '(', '"', '!', ',', '(', ')', '\t' }; string[] words = docTextString.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); int i = 0; string aWord; char[] trimEndChars = new char[] { ';', '.', '"', ',', '\r', ':', ']', '!', '?', '+', '(', ')', '\'', '{', '}', '-', '`', '/', '=' }; char[] trimStartChars = new char[] { ';', '&', '-', '#', '*', '[', '.', '"', ',', '\r', ')', '(', '\'', '{', '}', '-', '`' }; foreach (string wordStr in words) { i++; aWord = wordStr.TrimEnd(trimEndChars); aWord = aWord.TrimStart(trimStartChars); if (aWord.Length > 1 && excludedWords.Contains(aWord) == false) { indexRoot.Lexicon.PossiblyAddToken(aWord, doc); } } }
public override void Visit(DocumentText text) { base.Visit(text); RichTextRunFont runFont = CreateRichTextRun(text.TextProperties); richTextString.AddTextRun(text.Text, runFont); }
//Calls the server and ask for a document. public void openFile(string nameOfFile) { if (hasLock == false) { try { if (nameOfFile != "") { //Network call. openDocument = network.openFile(nameOfFile, myInfo); //Clears the text box. DocumentText.Document.Blocks.Clear(); //Appends the grabbed document. DocumentText.AppendText(openDocument.FileContents); //Sets current textbox string for the thread to send and recieve changes. currentTextboxText = openDocument.FileContents; //Unlocks the lock request and drop buttons. lockRequest.IsEnabled = true; releaseLock.IsEnabled = true; } } catch (Exception err) { onDisconnect(err); } } else { releaseLock_Click(null, null); openFile(nameOfFile); //System.Windows.MessageBox.Show("Please release the lock before opening a new file.", "Error"); } }
internal Token GetKeyword(DocumentText source, int startPos, int endPos) { int num = endPos - startPos; Keyword keyword = this; label_9: while (keyword != null) { if (num == keyword.length) { string str = keyword.name; int index1 = 1; int index2 = startPos + 1; while (index1 < num) { if ((int)str[index1] != (int)source[index2]) { keyword = keyword.next; goto label_9; } else { ++index1; ++index2; } } return(keyword.token); } keyword = keyword.next; } return(Token.Identifier); }
public override void Visit(DocumentText text) { if (!fonts.Contains(text.TextProperties.FontName)) { fonts.Add(text.TextProperties.FontName); } }
public async Task <IActionResult> Create([FromBody] DocumentCreateDto document) { if (document == null) { return(BadRequest()); } int attemptsCount = 0; int maxAttemptsCount = 100; string slug; bool isSlugUnique = false; do { slug = document.Title.GenerateSlug(); isSlugUnique = (await _db.Documents.SingleOrDefaultAsync(d => d.Slug == slug)) == null; } while (!isSlugUnique && attemptsCount < maxAttemptsCount); if (!isSlugUnique) { return(BadRequest(new { message = "Cannot generate unique slug" })); } var newDocument = new Documents { ParentDocumentId = document.ParentDocumentId, ProjectId = document.ProjectId, CreatorId = UserId, Slug = slug, Title = document.Title, Subtitle = document.Subtitle, DateCreated = DateTime.UtcNow, IsDraft = document.IsDraft }; _db.Documents.Add(newDocument); await _db.SaveChangesAsync(); await _db.Entry(newDocument).Reference(d => d.Creator).LoadAsync(); var newDocumentText = new DocumentText { DocumentId = newDocument.DocumentId, EditorId = UserId, Content = document.Content, QuillDelta = document.QuillDelta, TimeUpdated = DateTime.UtcNow }; _db.DocumentText.Add(newDocumentText); await _db.SaveChangesAsync(); await this.SaveActivity(newDocument.DocumentId, @"Document created: " + newDocument.Title, new { document_id = newDocument.DocumentId, type = "create" }); return(Ok(await PrepareDocument(newDocument))); }
public override void Visit(DocumentText text) { string prefix = (text.TextProperties.FontBold) ? "**" : ""; Buffer.Append(prefix); Buffer.Append(text.Text); Buffer.Append(prefix); }
public void DoCut() { var selectionIndex = access.GetSelectedIndex(); var selectionLength = access.GetSelectionLength(); CopiedText = access.GetSelectedText(); DocumentText = DocumentText.Remove(selectionIndex, selectionLength); }
//hash code trait public override int GetHashCode() { unchecked { var hash = 0; hash = hash * 31 + FilePath.GetHashCode(); hash = hash * 31 + DocumentText.GetHashCode(); return(hash); } }
//pretty print public void Print(PrettyPrinter printer) { printer.Println("RdXamlStylerFormattingRequest ("); using (printer.IndentCookie()) { printer.Print("filePath = "); FilePath.PrintEx(printer); printer.Println(); printer.Print("documentText = "); DocumentText.PrintEx(printer); printer.Println(); } printer.Print(")"); }
protected override void Execute(CodeActivityContext context) { ExtractorDocumentType documentType = ExtractorDocumentType.Get(context); ResultsDocumentBounds documentBounds = DocumentBounds.Get(context); string text = DocumentText.Get(context); Document document = DocumentObjectModel.Get(context); string documentPath = DocumentPath.Get(context); ExtractorResult.Set(context, ComputeResult(documentType, documentBounds, text, document, documentPath)); }
protected override void Execute(CodeActivityContext context) { string text = DocumentText.Get(context); Document document = DocumentObjectModel.Get(context); string documentPath = DocumentPath.Get(context); ClassifierDocumentType[] documentTypes = DocumentTypes.Get(context); int evidencePage = EvidencePage.Get(context); ClassifierResult.Set(context, ComputeResult(text, document, documentPath, documentTypes, evidencePage)); }
public override IParser CreateParser(string fileName, int lineNumber, DocumentText text, Module symbolTable, ErrorNodeList errors, CompilerParameters options) { // Document document = this.CreateDocument(fileName, lineNumber, text); // return new Parser(symbolTable, document, errorNodes); // Document document = this.CreateDocument(fileName, lineNumber, text); Parser parser = new Parser(document, errors, symbolTable, options as ZonnonCompilerParameters); //Parser.debug = options is ZonnonCompilerParameters ? ((ZonnonCompilerParameters)options).Debug : false; //Parser.debugT = options is ZonnonCompilerParameters ? ((ZonnonCompilerParameters)options).DebugT : false; return(parser); }
/// <summary> /// Sends an image to the Azure Cognitive Vision and returns the rendered text. /// More information available at https://westcentralus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-1-ga/operations/5d986960601faab4bf452005 /// </summary> /// <param name="filename"></param> /// <returns></returns> public async Task <List <DocumentText> > ReadImage(Stream stream) { try { var streamHeaders = await ComputerVisionClient.ReadInStreamAsync(stream, "en"); var operationLocation = streamHeaders.OperationLocation; const int numberOfCharsInOperationId = 36; string operationId = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId); await Task.Delay(1000); ReadOperationResult readOperationResult; do { readOperationResult = await ComputerVisionClient.GetReadResultAsync(Guid.Parse(operationId)); } while (readOperationResult.Status == OperationStatusCodes.Running || readOperationResult.Status == OperationStatusCodes.NotStarted); var listOfDocumentText = new List <DocumentText>(); var arrayOfReadResults = readOperationResult.AnalyzeResult.ReadResults; foreach (var page in arrayOfReadResults) { foreach (var line in page.Lines) { var boundBox = new BoundingBox() { Left = line.BoundingBox[0], Top = line.BoundingBox[1], Right = line.BoundingBox[4], Bottom = line.BoundingBox[5] }; var documentText = new DocumentText() { BoundingBox = boundBox, Text = line.Text }; listOfDocumentText.Add(documentText); } } return(listOfDocumentText); } catch (Exception e) { Logger.LogError(e, $"failed to analyze file"); return(null); } }
public MainPage() { this.InitializeComponent(); ViewModel = new HomeViewModel(); if (!DesignMode.DesignModeEnabled) { this.WhenActivated(d => { d(this.Bind(ViewModel, vm => vm.Path, view => view.Path.Text)); d(this.Bind(ViewModel, vm => vm.Search, view => view.SearchBox.Text)); d(this.Bind(ViewModel, vm => vm.SelectedRow, view => view.Data.SelectedItem)); d(this.WhenAnyValue(view => view.ViewModel.Data.Documents) .Select(documents => documents.SelectMany(doc => doc.Data)) .BindTo(this, view => view.Data.ItemsSource)); d(this.WhenAnyValue(view => view.ViewModel.Data.Documents) .Select(documents => String.Join(Environment.NewLine, documents.Select(doc => doc.Text))) .BindTo(this, view => view.DocumentText.Text)); d(this.WhenAnyValue(view => view.ViewModel.Data.Documents) .Select(documents => documents.SelectMany(doc => doc.Data)) .BindTo(this, view => view.SearchBox.AutoCompleteSource)); d(this.WhenAnyValue(view => view.ViewModel.SelectedRow) .Where(row => row != null) .Select(row => ViewModel.GetSelectionForData(row, DocumentText.Text)) .Do(selection => DocumentText.Select(selection.start, selection.end - selection.start)) .Subscribe()); d(this.BindCommand(ViewModel, vm => vm.LoadPath, view => view.PathPicker)); d(ViewModel.LoadPathInteraction.RegisterHandler(async ctx => { var picker = new FileOpenPicker { ViewMode = PickerViewMode.List, SuggestedStartLocation = PickerLocationId.DocumentsLibrary }; picker.FileTypeFilter.Add(".xml"); var file = await picker.PickSingleFileAsync(); if (file != null) { StorageApplicationPermissions.FutureAccessList.Add(file); } ctx.SetOutput(file?.Path); })); }); } }
static void createDocumentInvertedIndex(SessionBase session, Database db, BTreeSet <Document> documentSet) { UInt32 dbNum = db.DatabaseNumber; Document doc = null; Document inputDoc = new Document(db.Id); Placement wordPlacement = new Placement(inputDoc.DatabaseNumber, 20000, 1, 25000, 65000, true, false, 1, false); Placement wordHitPlacement = new Placement(inputDoc.DatabaseNumber, 40000, 1, 25000, 65500, true, false, 1, false); //session.SetTraceDbActivity(db.DatabaseNumber); BTreeSetIterator <Document> iterator = documentSet.Iterator(); iterator.GoTo(inputDoc); inputDoc = iterator.Current(); while (inputDoc != null && inputDoc.Page.Database.DatabaseNumber == dbNum) { doc = (Document)session.Open(inputDoc.Page.Database, inputDoc.Id); // if matching database is availeble, use it to speed up lookup DocumentText docText = doc.Content; string text = docText.Text.ToLower(); MatchCollection tagMatches = Regex.Matches(text, "[a-z][a-z.$]+"); UInt64 wordCt = 0; WordHit wordHit; Word word; if (++s_docCountIndexed % 50000 == 0) { Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed); } BTreeSetOidShort <Word> wordSet = doc.WordSet; foreach (Match m in tagMatches) { word = new Word(m.Value); if (wordSet.TryGetKey(word, ref word)) { //wordHit = doc.WordHit[word]; // to costly to add tight now - figure out a better way ? //wordHit.Add(wordCt); } else { word = new Word(m.Value); word.Persist(wordPlacement, session); wordSet.Add(word); wordHit = new WordHit(doc, wordCt++, session); //wordHit.Persist(wordHitPlacement, session); doc.WordHit.ValuePlacement = wordHitPlacement; doc.WordHit.AddFast(word, wordHit); } } inputDoc = iterator.Next(); } session.FlushUpdates(db); session.ClearCachedObjects(db); // free up memory for objects we no longer need to have cached Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed + " Database: " + dbNum + " is completed."); }
public override void Visit(DocumentText text) { if (activeBlock == null) { throw new InvalidOperationException("No active block"); } var page = layoutVisitor.GetPage(text.Position); if (page >= pages.Count) { VisitPage(); } activeBlock.AddText(text.Text); }
public DocumentText GetText() { var size = GetSize(); int bufferSize = (int)size.Characters; var tBuffer = new ushort[bufferSize]; var aBuffer = new ushort[bufferSize]; uint numChars = 0; doc.GetText(0, ref tBuffer[0], ref aBuffer[0], ref numChars, size.Characters); DocumentText result = new DocumentText(); result.Text = StringFromBuffer(tBuffer); result.Flags = aBuffer.Select(v => (SourceTextType)v).ToArray(); return(result); }
public async Task RazorCSharpFormattingAsync() { var options = new FormattingOptions() { TabSize = 4, InsertSpaces = true }; var range = TextSpan.FromBounds(0, DocumentText.Length).AsRange(DocumentText); var edits = await RazorFormattingService.FormatAsync(DocumentUri, DocumentSnapshot, range, options, CancellationToken.None); #if DEBUG // For debugging purposes only. var changedText = DocumentText.WithChanges(edits.Select(e => e.AsTextChange(DocumentText))); _ = changedText.ToString(); #endif }
void ReleaseDesignerOutlets() { if (ActionButton != null) { ActionButton.Dispose(); ActionButton = null; } if (DocumentText != null) { DocumentText.Dispose(); DocumentText = null; } if (SaveButton != null) { SaveButton.Dispose(); SaveButton = null; } }
public async Task RazorCSharpFormattingAsync() { var options = new FormattingOptions() { TabSize = 4, InsertSpaces = true }; var useSourceTextDiffer = DifferType != DifferType.GetTextChanges; options["UseSourceTextDiffer"] = new OmniSharp.Extensions.LanguageServer.Protocol.Models.BooleanNumberString(useSourceTextDiffer); var range = TextSpan.FromBounds(0, DocumentText.Length).AsRange(DocumentText); var edits = await RazorFormattingService.FormatAsync(DocumentUri, DocumentSnapshot, range, options, CancellationToken.None); #if DEBUG // For debugging purposes only. var changedText = DocumentText.WithChanges(edits.Select(e => e.AsTextChange(DocumentText))); _ = changedText.ToString(); #endif }
public async Task <IActionResult> SaveChanges([FromRoute] int?id, [FromRoute] string slug, [FromBody] DocumentTextSaveDto changes) { var document = await GetDocument(id, slug); if (document == null) { return(NotFound()); } var newText = new DocumentText { DocumentId = document.DocumentId, EditorId = UserId, Content = changes.Content, QuillDelta = changes.QuillDelta, TimeUpdated = DateTime.UtcNow }; _db.DocumentText.Add(newText); await _db.SaveChangesAsync(); return(Ok()); }
static void createDocumentInvertedIndex(IndexRoot indexRoot, Document doc) { if (!doc.Indexed) { DocumentText docText = doc.Content; string text = docText.Text.ToLower(); MatchCollection tagMatches = Regex.Matches(text, "[a-z][a-z$]+"); if (++s_docCountIndexed % 50000 == 0) { Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed); } foreach (Match m in tagMatches) { indexRoot.Lexicon.PossiblyAddToken(m.Value, doc); } if (s_docCountIndexed % 1000 == 0) { Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed + " Database: " + doc.DatabaseNumber + " is completed."); } doc.Indexed = true; } }
public void changes() { while (true) { if (openDocument != null) { List <Patch> patches; Dictionary <int, List <Patch> > returnedPatches; Object[] temp; while (true) { try { if (hasLock == true) { Thread.Sleep(1000); //Copies the document Textbox // TextRange range = new TextRange(DocumentText.Document.ContentStart, DocumentText.Document.ContentEnd); string myText2 = currentTextboxText; patches = diffMatch.patch_make(diffMatch.diff_main(openDocument.FileContents, myText2)); temp = diffMatch.patch_apply(patches, openDocument.FileContents); openDocument.FileContents = temp[0].ToString(); network.sendDocChanges(openDocument.FileName, patches, myInfo); openDocument.SaveID = network.getLastPatchID(openDocument.FileName) + 1; } else { Thread.Sleep(1000); returnedPatches = network.getDocChanges(openDocument.FileName, myInfo, openDocument.SaveID); if (returnedPatches.Count > 0) { foreach (List <Patch> item in returnedPatches.Values) { temp = diffMatch.patch_apply(item, openDocument.FileContents); openDocument.FileContents = temp[0].ToString(); this.Dispatcher.Invoke(new Action(() => { DocumentText.Document.Blocks.Clear(); DocumentText.AppendText(openDocument.FileContents); })); } openDocument.SaveID = returnedPatches.Last().Key + 1; } } } catch (Exception) { //MessageBoxResult result = System.Windows.MessageBox.Show("Error: Connection to the server was lost. Would you like to reconnect?", "Error", MessageBoxButton.YesNo); //if (result == MessageBoxResult.No) //{ // this.Close(); // Environment.Exit(1); //} } } } } }
/// <summary> /// Views the did load. /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); // Save the default text area height _documentTextHeight = DocumentText.Frame.Height; // var picker = new UIDocumentPickerViewController (srcURL, UIDocumentPickerMode.ExportToService); // Watch for a new document being created ThisApp.DocumentLoaded += (document) => { // Display the contents of the document DocumentText.Text = document.Contents; // Watch for the document being modified by an outside source document.DocumentModified += (doc) => { // Display the updated contents of the document DocumentText.Text = doc.Contents; Console.WriteLine("Document contents have been updated"); }; }; // Wireup events for the text editor DocumentText.ShouldBeginEditing = delegate(UITextView field){ //Placeholder MoveDocumentText(_documentTextHeight - 170f); return(true); }; DocumentText.ShouldEndEditing = delegate(UITextView field){ MoveDocumentText(_documentTextHeight); ThisApp.Document.Contents = DocumentText.Text; return(true); }; // Wireup the Save button SaveButton.Clicked += (sender, e) => { // Close the keyboard DocumentText.ResignFirstResponder(); // Save the changes to the document ThisApp.SaveDocument(); }; // Wireup the Action buttom ActionButton.Clicked += (s, e) => { // Allow the Document picker to select a range of document types var allowedUTIs = new string[] { UTType.UTF8PlainText, UTType.PlainText, UTType.RTF, UTType.PNG, UTType.Text, UTType.PDF, UTType.Image }; // Display the picker //var picker = new UIDocumentPickerViewController (allowedUTIs, UIDocumentPickerMode.Open); var pickerMenu = new UIDocumentMenuViewController(allowedUTIs, UIDocumentPickerMode.Open); pickerMenu.DidPickDocumentPicker += (sender, args) => { // Wireup Document Picker args.DocumentPicker.DidPickDocument += (sndr, pArgs) => { // IMPORTANT! You must lock the security scope before you can // access this file var securityEnabled = pArgs.Url.StartAccessingSecurityScopedResource(); // Open the document ThisApp.OpenDocument(pArgs.Url); // TODO: This should work but doesn't // Apple's WWDC 2014 sample project does this but it blows // up in Xamarin NSFileCoordinator fileCoordinator = new NSFileCoordinator(); NSError err; fileCoordinator.CoordinateRead(pArgs.Url, 0, out err, (NSUrl newUrl) => { NSData data = NSData.FromUrl(newUrl); Console.WriteLine("Data: {0}", data); }); // IMPORTANT! You must release the security lock established // above. pArgs.Url.StopAccessingSecurityScopedResource(); }; // Display the document picker PresentViewController(args.DocumentPicker, true, null); }; pickerMenu.ModalPresentationStyle = UIModalPresentationStyle.Popover; PresentViewController(pickerMenu, true, null); UIPopoverPresentationController presentationPopover = pickerMenu.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = this.View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Down; presentationPopover.SourceRect = ((UIButton)s).Frame; } }; }
public virtual CompilationUnitSnippet CreateCompilationUnitSnippet(string fileName, int lineNumber, DocumentText text, Compilation compilation){ Document doc = this.CreateDocument(Path.GetFullPath(fileName), 1, text); CompilationUnitSnippet cu = new CompilationUnitSnippet(); cu.Name = Identifier.For(doc.Name); cu.SourceContext = new SourceContext(doc); cu.Compilation = compilation; return cu; }
public virtual Document CreateDocument(string fileName, int lineNumber, DocumentText text){ Debug.Assert(false); return null; }
public IParser CreateParser(string fileName, int lineNumber, DocumentText text, Module symbolTable, ErrorNodeList errorNodes, CompilerParameters options){ return new ResgenCompilerStub(errorNodes, options as CompilerOptions, this.pathToResgen); }
private static Guid ZonnonDebugGuid = new Guid("8FFA4FA4-F168-43e2-99BE-E50F6D6D3389"); // NEW R public override Document CreateDocument(string fileName, int lineNumber, DocumentText text) { /// return new Document(fileName,lineNumber,text,SymDocumentType.Text, /// Compiler.ZonnonDebugGuid,SymLanguageVendor.Microsoft); return(ZonnonCompiler.CreateZonnonDocument(fileName, lineNumber, text)); }
public static Document CreateZonnonDocument(string fileName, int lineNumber, DocumentText text) { //TODO: allocate a GUID for ETH and supply this in the place of SymLanguageVendor.Microsoft return(new Document(fileName, lineNumber, text, SymDocumentType.Text, ZonnonCompiler.ZonnonDebugGuid, SymLanguageVendor.Microsoft)); }
public static ComplexIdentifier ComplexIdentifierFor(DocumentText text, int offset, int length) { return(new ComplexIdentifier(text, offset, length)); }
public virtual IParser CreateParser(string fileName, int lineNumber, DocumentText text, Module symbolTable, ErrorNodeList errorNodes, CompilerParameters options){ Debug.Assert(false); return null; }
public Document(string name, DocumentText text) { this.Name = name; this.Text = text; }