private static TiledTextPart GetTiledTextPart(int rowCount)
        {
            TiledTextPart part = new TiledTextPart
            {
                ItemId    = Guid.NewGuid().ToString(),
                CreatorId = "zeus",
                UserId    = "zeus"
            };
            char c = 'a';

            for (int y = 0; y < rowCount; y++)
            {
                TextTileRow row = new TextTileRow
                {
                    Y = y + 1
                };
                part.Rows.Add(row);

                for (int x = 0; x < 3; x++)
                {
                    TextTile tile = new TextTile
                    {
                        X = x + 1,
                    };
                    tile.Data[TextTileRow.TEXT_DATA_NAME] = $"{c}{x + 1}";
                    row.Tiles.Add(tile);
                    if (++c > 'z')
                    {
                        c = 'a';
                    }
                }
            }
            return(part);
        }
Exemplo n.º 2
0
        private void AddTiles(IEnumerable <XElement> wElements, TextTileRow row)
        {
            int x = 1;

            foreach (XElement w in wElements)
            {
                TextTile tile = new()
                {
                    X = x++
                };
                // w's attributes
                foreach (XAttribute attr in w.Attributes())
                {
                    string key = GetKeyFromAttrName(attr.Name);
                    tile.Data[key] = attr.Value;
                }
                var textAndPatch = GetTextAndPatch(w.Value);
                if (textAndPatch != null)
                {
                    tile.Data[KEY_TEXT]  = textAndPatch.Item1;
                    tile.Data[KEY_PATCH] = textAndPatch.Item2;
                }
                else
                {
                    tile.Data[KEY_TEXT] = w.Value;
                }
                row.Tiles.Add(tile);
            }
        }
Exemplo n.º 3
0
        private void AddTiles(IEnumerable <Tuple <string, string> > wordAndIds,
                              TextTileRow row)
        {
            int x = 1;

            foreach (var wi in wordAndIds)
            {
                TextTile tile = new()
                {
                    X = x++
                };
                var textAndPatch = GetTextAndPatch(wi.Item1);
                if (textAndPatch != null)
                {
                    tile.Data[KEY_TEXT]  = textAndPatch.Item1;
                    tile.Data[KEY_PATCH] = textAndPatch.Item2;
                }
                else
                {
                    tile.Data[KEY_TEXT] = wi.Item1;
                }

                tile.Data["id"] = wi.Item2;
                row.Tiles.Add(tile);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates and seeds a new part.
        /// </summary>
        /// <param name="item">The item this part should belong to.</param>
        /// <param name="roleId">The optional part role ID.</param>
        /// <param name="factory">The part seeder factory. This is used
        /// for layer parts, which need to seed a set of fragments.</param>
        /// <returns>A new part.</returns>
        /// <exception cref="ArgumentNullException">item or factory</exception>
        public override IPart GetPart(IItem item, string roleId,
                                      PartSeederFactory factory)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            TiledTextPart part = new TiledTextPart();

            SetPartMetadata(part, roleId, item);

            // citation
            part.Citation = Randomizer.Seed.Next(1, 100)
                            .ToString(CultureInfo.InvariantCulture);

            // from 2 to 10 rows
            var    faker = new Faker();
            string text  = faker.Lorem.Sentences(
                Randomizer.Seed.Next(2, 11));
            int y = 1;

            foreach (string line in text.Split('\n'))
            {
                // row
                TextTileRow row = new TextTileRow
                {
                    Y = y++,
                };
                // row's data
                for (int i = 0; i < Randomizer.Seed.Next(0, 4); i++)
                {
                    row.Data[$"d{(char)(i + 97)}"] = faker.Lorem.Word();
                }

                // add tiles in row
                int x = 1;
                foreach (string token in line.Trim().Split(' '))
                {
                    TextTile tile = new TextTile
                    {
                        X = x++,
                    };
                    // text
                    tile.Data[TextTileRow.TEXT_DATA_NAME] = token;
                    // other data
                    for (int i = 0; i < Randomizer.Seed.Next(0, 11); i++)
                    {
                        tile.Data[$"d{(char)(i + 97)}"] = faker.Lorem.Word();
                    }
                    row.Tiles.Add(tile);
                }

                part.Rows.Add(row);
            }

            return(part);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Imports the partition into a Cadmus item.
        /// </summary>
        /// <param name="div">The document's div element containing the partition,
        /// or a part of it.</param>
        /// <param name="rowElements">The rows elements, i.e. the children elements
        /// of the partition representing tiled text rows (either <c>l</c> or
        /// <c>p</c> elements).</param>
        /// <returns>The item.</returns>
        private IItem ImportPartition(XElement div,
                                      IList <XElement> rowElements)
        {
            _partitionNr++;

            // build citation
            string cit = XmlHelper.GetBreakPointCitation(_partitionNr,
                                                         div.Elements().FirstOrDefault(IsLOrP),
                                                         _docId);

            // item
            var  nBounds = GetPartitionNBoundaries(rowElements);
            Item item    = new Item
            {
                Title = cit,
                //Description = (nBounds != null ?
                //    $"{nBounds.Item1}-{nBounds.Item2} " : "") +
                //    GetDescriptionText(div.Value.Trim()),
                FacetId   = _facetId,
                GroupId   = _docId,
                CreatorId = _userId,
                UserId    = UserId
            };

            // text part
            TiledTextPart part = new TiledTextPart
            {
                ItemId    = item.Id,
                Citation  = cit,
                CreatorId = item.CreatorId,
                UserId    = item.UserId,
                RoleId    = PartBase.BASE_TEXT_ROLE_ID
            };

            item.Parts.Add(part);

            int y      = 1;
            int wordNr = 1;

            foreach (XElement rowElement in rowElements)
            {
                // row
                TextTileRow row = new TextTileRow
                {
                    Y = y++
                };
                row.Data["_name"] = rowElement.Name.LocalName;

                // row's attributes
                foreach (XAttribute attr in rowElement.Attributes())
                {
                    string key = GetKeyFromAttrName(attr.Name);
                    row.Data[key] = attr.Value;
                }

                // tiles
                if (rowElement.Elements(XmlHelper.TEI + "w").Any())
                {
                    AddTiles(rowElement.Elements(XmlHelper.TEI + "w"), row);
                }
                else
                {
                    int divNr = div.ElementsBeforeSelf(div.Name).Count() + 1;
                    row.Data["_split"] = "1";
                    var wordAndIds = from w in rowElement.Value.Split(' ')
                                     select Tuple.Create(
                        w,
                        $"d{divNr:000}w{wordNr++}");

                    AddTiles(wordAndIds, row);
                }

                part.Rows.Add(row);
            }

            item.Description = (nBounds != null ?
                                $"{nBounds.Item1}-{nBounds.Item2} " : "")
                               + GetPartTextDescription(part);

            item.SortKey = _sortKeyBuilder.BuildKey(item, null);
            int i = item.SortKey.IndexOf(' ', item.SortKey.IndexOf(' ') + 1);

            item.SortKey = item.SortKey.Substring(0, i);

            return(item);
        }