예제 #1
0
        /// <summary>
        /// Creates a immutable dependency graph
        /// </summary>
        /// <param name="dataFormat"> a data format that describes the label types (or the columns in the input and output) </param>
        /// <param name="sourceGraph"> a dependency graph that implements the interface org.maltparser.core.syntaxgraph.DependencyStructure </param>
        /// <param name="defaultRootLabel"> the default root label </param>
        /// <exception cref="MaltChainedException"> </exception>
        public ConcurrentDependencyGraph(DataFormat.DataFormat dataFormat, IDependencyStructure sourceGraph, string defaultRootLabel)
        {
            DataFormat = dataFormat;

            nodes = new ConcurrentDependencyNode[sourceGraph.NDependencyNode()];

            // Add nodes
            nodes[0] = new ConcurrentDependencyNode(this, 0, null); // ROOT

            foreach (int index in sourceGraph.TokenIndices)
            {
                DependencyNode gNode = sourceGraph.GetDependencyNode(index);

                string[] columns = new string[dataFormat.NumberOfColumns()];

                for (int i = 0; i < dataFormat.NumberOfColumns(); i++)
                {
                    ColumnDescription column = dataFormat.GetColumnDescription(i);

                    if (!column.Internal)
                    {
                        if (column.Category == ColumnDescription.Input)
                        {
                            columns[i] = gNode.getLabelSymbol(sourceGraph.SymbolTables.getSymbolTable(column.Name));
                        }
                        else if (column.Category == ColumnDescription.Head)
                        {
                            if (gNode.hasHead())
                            {
                                columns[i] = Convert.ToString(gNode.HeadEdge.Source.Index);
                            }
                            else
                            {
                                columns[i] = Convert.ToString(-1);
                            }
                        }
                        else if (column.Category == ColumnDescription.DependencyEdgeLabel)
                        {
                            SymbolTable sourceTable = sourceGraph.SymbolTables.getSymbolTable(column.Name);

                            if (gNode.HeadEdge.hasLabel(sourceTable))
                            {
                                columns[i] = gNode.HeadEdge.getLabelSymbol(sourceTable);
                            }
                            else
                            {
                                columns[i] = defaultRootLabel;
                            }
                        }
                        else
                        {
                            columns[i] = "_";
                        }
                    }
                }
                nodes[index] = new ConcurrentDependencyNode(this, index, columns);
            }
        }
예제 #2
0
        internal ConcurrentDependencyEdge(DataFormat.DataFormat dataFormat, ConcurrentDependencyNode source, ConcurrentDependencyNode target, SortedDictionary <int, string> labels)
        {
            Source = source ?? throw new ConcurrentGraphException("Not allowed to have an edge without a source node");

            Target = target ?? throw new ConcurrentGraphException("Not allowed to have an edge without a target node");

            if (Target.Index == 0)
            {
                throw new ConcurrentGraphException("Not allowed to have an edge target as root node");
            }

            this.labels = new SortedDictionary <int, string>();

            if (labels != null)
            {
                foreach (int i in labels.Keys)
                {
                    if (dataFormat.GetColumnDescription(i).Category == ColumnDescription.DependencyEdgeLabel)
                    {
                        this.labels[i] = labels[i];
                    }
                }
            }
        }