Пример #1
0
 public AnnotatedDocument(
     List<AnnotationModel> annotations, 
     DocumentModel document)
 {
     this.Annotations = annotations;
     this.Document = document;
     this.Document.ClearLinkedAnnotations();
     var r = new Regex(@"\p{IsArabic}|\p{IsHebrew}");
     this.isRTL = r.IsMatch(this.Document.Body);
     this.Annotators = this.Annotations.Select(i => i.Author).Distinct().ToList();
     for (int i = 0; i < this.Annotations.Count; i++) {
         var annotation = this.Annotations[i];
         if (annotation.TokenRange == null) {
             continue;
         }
         int start = annotation.TokenRange.StartIdx;
         int range = annotation.TokenRange.Range;
         for(int j = start; j < start + range; j++) {
             if (this.Document.Tokens[j].LinkedAnnotations.Contains(i)) {
                 continue;
             }
             this.Document.Tokens[j].LinkedAnnotations.Add(i);
             var a = this.Document.Tokens[j].TokenVal;
             var b = annotation.Body;
         }
     }
 }
Пример #2
0
 public AnnotationModel(string author, string body, DocumentModel fullText, bool isArchived)
 {
     this.Author = author;
     this.Body = body;
     if (this.Body.Length <= PREVIEW_LENGTH) {
         this.PreviewText = this.Body;
     } else {
         this.PreviewText = this.Body.Substring(0, 200) + "...";
     }
     this.setAnnotationBodyUnits(fullText);
     this.IsStarred = false;
     this.IsArchived = isArchived;
 }
Пример #3
0
        private void setAnnotationBodyUnits(DocumentModel fullText)
        {
            if (fullText == null) {
                throw new ArgumentNullException("fullText");
            }
            this.AnnotationBodyUnits = new TokenizedAnnotation();
            var indices = this.backTickIndices();
            int lastIdx = 0;
            for (int i = 0; i < indices.Count; i += 2) {
                if (i == indices.Count - 1) {
                    break;
                }
                int idx1 = indices[i];
                int idx2 = indices[i + 1];
                string prefix = this.Body.Substring(lastIdx, idx1);
                this.AnnotationBodyUnits.Add(prefix);
                string annotationString = this.Body.Substring(idx1, idx2).Trim('`');
                this.TokenRange = fullText.GetTokenRange(annotationString);

                this.AnnotationBodyUnits.Add(annotationString, linkedText:true);
                lastIdx = idx2;
            }
            string suffix = string.Concat(this.Body.Skip(lastIdx));
            this.AnnotationBodyUnits.Add(suffix);
            this.AnnotationPreviewUnits = new TokenizedAnnotation();

            foreach (var unit in this.AnnotationBodyUnits.Tokens) {
                int curLength = 0;
                int toTake = Math.Min(unit.Val.Length, PREVIEW_LENGTH - curLength);
                string val = unit.Val.Substring(0, toTake);
                this.AnnotationPreviewUnits.Add(val, unit.linkedText);
                curLength += val.Length;
                if (curLength > PREVIEW_LENGTH) {
                    continue;
                }
            }
        }
Пример #4
0
 internal static AnnotationModel Random(DocumentModel doc)
 {
     int maxTokensToTake = Math.Min(20, doc.Tokens.Count);
     var text = File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/Placeholder2.txt"));
     var tokenCount = doc.Tokens.Count;
     var startIdx = rand.Next(tokenCount - maxTokensToTake);
     int toTake = rand.Next(maxTokensToTake);
     var quoted = string.Concat(doc.Tokens.Skip(startIdx).Take(toTake).Select(i => i.AsString));
     var textLength = text.Length;
     int textStart = rand.Next(textLength);
     int textToTake = rand.Next(1000);
     var body = string.Format("`{0}`", quoted) +
         string.Concat(text.Skip(textStart).Take(Math.Min(textToTake, textLength - textStart)));
     var toReturn = new AnnotationModel("test", body, doc, isArchived:false);
     toReturn.Id = Guid.NewGuid();
     return toReturn;
 }
Пример #5
0
 internal static AnnotationModel FromDictionary(Dictionary<string, string> dict, DocumentModel doc)
 {
     bool isArchived = false;
     if (dict.ContainsKey("IsArchived")) {
         isArchived = bool.Parse(dict["IsArchived"]);
     }
     var toReturn = new AnnotationModel(dict["Author"], dict["Body"], doc, isArchived);
     toReturn.Id = Guid.Parse(dict["AnnotationId"]);
     return toReturn;
 }
Пример #6
0
 public List<AnnotationModel> GetAnnotations(Guid documentId, DocumentModel doc)
 {
     //TODO: check the permissions on this user
     var a = this.get(DOCUMENT_ANNOTATIONS_TABLE, "DocumentId", documentId.ToString());
     if (a.Count == 0) {
         return new List<AnnotationModel>();
     }
     var ids = JArray.Parse(a[0]["AnnotationIds"]);
     var annotations = ids.Select(i => this.get(ANNOTATION_TABLE, "AnnotationId", i.ToString()));
     return annotations.Select(i => AnnotationModel.FromDictionary(i[0], doc)).ToList();
 }
Пример #7
0
 public bool AddDocument(DocumentModel doc)
 {
     this.add(DOCUMENTS_TABLE, "DocumentId", doc.Id.ToString(),
         new TableAttribute("Body", doc.Body));
     this.setDocumentInfo(doc.Info);
     var ids = this.getUserDocumentIds(doc.Owner).ToList();
     if (ids.Any(i => i.ToString() == doc.Id.ToString())) {
         return true;
     }
     ids.Add(doc.Id);
     JArray a = new JArray();
     foreach (var id in ids) {
         a.Add(id);
     }
     this.add(USER_DOCUMENTS, "UserId", doc.Owner,
         new TableAttribute("DocumentIds", a.ToString()));
     return true;
 }