Ejemplo n.º 1
0
        internal void SerializeStateEntries(StreamMarshaler streamBuffer, bool tagsCannotSpanOverMultipleArcs, float[] pWeights, ref uint iArcOffset, ref int iOffset)
        {
            List <Arc> list = _outArcs.ToList();

            list.Sort();
            Arc arc = (list.Count > 0) ? list[list.Count - 1] : null;
            IEnumerator <Arc> enumerator = ((IEnumerable <Arc>)list).GetEnumerator();

            enumerator.MoveNext();
            uint num  = (uint)(list.Count + (int)iArcOffset);
            uint num2 = num;

            foreach (Arc item in list)
            {
                int semanticTagCount = item.SemanticTagCount;
                if (semanticTagCount > 0)
                {
                    item.SetArcIndexForTag(0, iArcOffset, tagsCannotSpanOverMultipleArcs);
                }
                if (semanticTagCount <= 1)
                {
                    pWeights[iOffset++] = item.Serialize(streamBuffer, arc == item, iArcOffset++);
                }
                else
                {
                    iArcOffset++;
                    pWeights[iOffset++] = Arc.SerializeExtraEpsilonWithTag(streamBuffer, item, arc == item, num);
                    num = (uint)((int)num + (semanticTagCount - 1));
                }
            }
            enumerator = ((IEnumerable <Arc>)list).GetEnumerator();
            enumerator.MoveNext();
            num = num2;
            foreach (Arc item2 in list)
            {
                int semanticTagCount2 = item2.SemanticTagCount;
                if (semanticTagCount2 > 1)
                {
                    for (int i = 1; i < semanticTagCount2 - 1; i++)
                    {
                        item2.SetArcIndexForTag(i, iArcOffset, tagsCannotSpanOverMultipleArcs);
                        num++;
                        pWeights[iOffset++] = Arc.SerializeExtraEpsilonWithTag(streamBuffer, item2, true, num);
                        iArcOffset++;
                    }
                    item2.SetArcIndexForTag(semanticTagCount2 - 1, iArcOffset, tagsCannotSpanOverMultipleArcs);
                    pWeights[iOffset++] = item2.Serialize(streamBuffer, true, iArcOffset++);
                    num++;
                }
            }
        }
Ejemplo n.º 2
0
        internal void SerializeStateEntries(StreamMarshaler streamBuffer, bool tagsCannotSpanOverMultipleArcs, float[] pWeights, ref uint iArcOffset, ref int iOffset)
        {
            // The arcs must be sorted before being written to disk.
            List <Arc> outArcs = _outArcs.ToList();

            outArcs.Sort();
            Arc lastArc = outArcs.Count > 0 ? outArcs[outArcs.Count - 1] : null;

            IEnumerator <Arc> enumArcs = ((IEnumerable <Arc>)outArcs).GetEnumerator();

            enumArcs.MoveNext();

            uint nextAvailableArc     = (uint)outArcs.Count + iArcOffset;
            uint saveNextAvailableArc = nextAvailableArc;

            // Write the arc of the first epsilon arc with an arc has more than one semantic tag
            foreach (Arc arc in outArcs)
            {
                // Create the first arc.
                int cSemantics = arc.SemanticTagCount;

                // Set the semantic property reference for the first arc
                if (cSemantics > 0)
                {
                    arc.SetArcIndexForTag(0, iArcOffset, tagsCannotSpanOverMultipleArcs);
                }

                // Serialize the arc
                if (cSemantics <= 1)
                {
                    pWeights[iOffset++] = arc.Serialize(streamBuffer, lastArc == arc, iArcOffset++);
                }
                else
                {
                    // update the position of the current arc
                    ++iArcOffset;

                    // more than one arc, create an epsilon transition
                    pWeights[iOffset++] = Arc.SerializeExtraEpsilonWithTag(streamBuffer, arc, lastArc == arc, nextAvailableArc);

                    // reset the position of the next available slop for an arc
                    nextAvailableArc += (uint)cSemantics - 1;
                }
            }

            enumArcs = ((IEnumerable <Arc>)outArcs).GetEnumerator();
            enumArcs.MoveNext();

            // revert the position for the new arc
            nextAvailableArc = saveNextAvailableArc;

            // write the additional arcs if we have more than one semantic tag
            foreach (Arc arc in outArcs)
            {
                int cSemantics = arc.SemanticTagCount;

                if (cSemantics > 1)
                {
                    // If more than 2 arcs insert extra new epsilon states, one per semantic tag
                    for (int i = 1; i < cSemantics - 1; i++)
                    {
                        // Set the semantic property reference
                        arc.SetArcIndexForTag(i, iArcOffset, tagsCannotSpanOverMultipleArcs);

                        // reset the position of the next available slop for an arc
                        nextAvailableArc++;

                        // create an epsilon transition
                        pWeights[iOffset++] = Arc.SerializeExtraEpsilonWithTag(streamBuffer, arc, true, nextAvailableArc);

                        // update the position of the current arc
                        ++iArcOffset;
                    }

                    // Set the semantic property reference
                    arc.SetArcIndexForTag(cSemantics - 1, iArcOffset, tagsCannotSpanOverMultipleArcs);

                    // Add the real arc at the end
                    pWeights[iOffset++] = arc.Serialize(streamBuffer, true, iArcOffset++);

                    // reset the position of the next available slop for an arc
                    nextAvailableArc++;
                }
            }
        }