Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a35cb648

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Added comments to backend

Zobrazit rozdíly:

Backend/Core/ZipUtils/Export.cs
10 10

  
11 11
namespace Core.ZipUtils
12 12
{
13
    /// <summary>
14
    /// Static methods for database exporting
15
    /// </summary>
13 16
    public class Export
14 17
    {
18
        /// <summary>
19
        /// Exports the specified annotations
20
        /// </summary>
21
        /// <param name="documents">list of documents to export</param>
22
        /// <param name="documentAnnotations">document-annotations to export mapping</param>
23
        /// <param name="documentFinalAnnotations">document-final annotations to export mapping</param>
24
        /// <param name="annotationTags">annotation-annotation tags mapping</param>
25
        /// <param name="finalAnnotationTags">final annotation-final annotation tags mapping</param>
26
        /// <returns></returns>
15 27
        public static MemoryStream FullExport(List<Document> documents, Dictionary<Document, List<Annotation>> documentAnnotations, Dictionary<Document, FinalAnnotation> documentFinalAnnotations,
16 28
            Dictionary<Annotation, List<AnnotationTag>> annotationTags, Dictionary<FinalAnnotation, List<FinalAnnotationTag>> finalAnnotationTags)
17 29
        {
18 30
            MemoryStream ms = new MemoryStream();
31
            // Set keepOpen to true so that Dispose() does not close the MemoryStream
19 32
            var archive = new ZipArchive(ms, ZipArchiveMode.Create, true);
20 33

  
21 34
            for (int docIndex = 0; docIndex < documents.Count; docIndex++)
......
37 50
                    CreateFile(documentDir + $"/annotation_{annotationIndex:00000}.json", annotationInfoJson, archive);
38 51
                }
39 52

  
53
                // Deal with final annotation if it exists
40 54
                var finalAnnotation = documentFinalAnnotations[document];
41 55
                if (finalAnnotation == null)
42 56
                {
......
48 62
                CreateFile(documentDir + "/final.json", finalAnnotationInfoJson, archive);
49 63
            }
50 64

  
65
            // Dispose of archive to close the header
51 66
            archive.Dispose();
52 67
            ms.Position = 0;
53 68
            return ms;
54 69
        }
55 70

  
71
        /// <summary>
72
        /// Creates a file and writes to it
73
        /// </summary>
74
        /// <param name="path">path to file</param>
75
        /// <param name="fileContent">string to write</param>
76
        /// <param name="archive">archive to write it to</param>
56 77
        private static void CreateFile(string path, string fileContent, ZipArchive archive)
57 78
        {
58 79
            var entry = archive.CreateEntry(path);
......
61 82
            entryStream.Close();
62 83
        }
63 84

  
85
        /// <summary>
86
        /// Dumps a Document into JSON-serialized ExportDocumentInfo
87
        /// </summary>
88
        /// <param name="document">Document to serialize</param>
89
        /// <returns>JSON-serialized ExportDocumentInfo</returns>
64 90
        private static string DumpDocument(Document document)
65 91
        {
66 92
            ExportDocumentInfo documentInfo = new();
......
71 97
            return JsonConvert.SerializeObject(documentInfo);
72 98
        }
73 99

  
100
        /// <summary>
101
        /// Dumps annotation into JSON-serialized ExportAnnotationInfo
102
        /// </summary>
103
        /// <param name="annotation">Annotation to dump</param>
104
        /// <param name="tags">Tags related to the annotation</param>
105
        /// <param name="documentId">Id of the document the annotation is related to</param>
106
        /// <returns>JSON-serialized ExportAnnotationInfo</returns>
74 107
        private static string DumpAnnotation(Annotation annotation, List<AnnotationTagGeneric> tags, Guid documentId)
75 108
        {
76 109
            ExportAnnotationInfo annotationInfo = new();
......
108 141

  
109 142
    public class ExportDocumentInfo
110 143
    {
144
        /// <summary>
145
        /// Document name
146
        /// </summary>
111 147
        public string Name { get; set; }
148
        /// <summary>
149
        /// Original document content
150
        /// </summary>
112 151
        public string Content { get; set; }
152
        /// <summary>
153
        /// Id of the document
154
        /// </summary>
113 155
        public Guid DocumentId { get; set; }
114 156
    }
115 157

  
116 158
    public class ExportAnnotationInfo
117 159
    {
160
        /// <summary>
161
        /// Annotator Id
162
        /// </summary>
118 163
        public Guid AnnotatorId { get; set; }
164
        /// <summary>
165
        /// Document Id
166
        /// </summary>
119 167
        public Guid DocumentId { get; set; }
168
        /// <summary>
169
        /// Tags 
170
        /// </summary>
120 171
        public List<ExportTagInstanceInfo> Tags { get; set; } = new();
121 172
    }
122 173

  
123 174
    public class ExportTagInstanceInfo
124 175
    {
176
        /// <summary>
177
        /// Tag category
178
        /// </summary>
125 179
        public string Category { get; set; }
180
        /// <summary>
181
        /// Name of the tag (the primary identifier)
182
        /// </summary>
126 183
        public string TagName { get; set; }
184
        /// <summary>
185
        /// Name of the subtag (the primary identifier of a subtag)
186
        /// </summary>
127 187
        public string? SubTagName { get; set; }
188
        /// <summary>
189
        /// Id of the instance (in case of multipart tags multiple tags share the same Id)
190
        /// </summary>
128 191
        public Guid InstanceId { get; set; }
192
        /// <summary>
193
        /// Position in the original document
194
        /// </summary>
129 195
        public int FirstCharPosition { get; set; }
196
        /// <summary>
197
        /// Length of the section in chars
198
        /// </summary>
130 199
        public int Length { get; set; }
200
        /// <summary>
201
        /// Optional sentiment
202
        /// </summary>
131 203
        public string? Sentiment { get; set; }
132 204
    }
133 205
}

Také k dispozici: Unified diff