Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readFeatureModel(org.w3c.dom.Element featuremodel, org.maltparser.core.feature.spec.SpecificationModels featureSpecModels) throws org.maltparser.core.exception.MaltChainedException
        private void readFeatureModel(Element featuremodel, SpecificationModels featureSpecModels)
        {
            int      specModelIndex = featureSpecModels.NextIndex;
            NodeList submodelList   = featuremodel.getElementsByTagName("submodel");

            if (submodelList.Length == 0)
            {
                NodeList featureList = featuremodel.getElementsByTagName("feature");
                for (int i = 0; i < featureList.Length; i++)
                {
                    string featureText = ((Element)featureList.item(i)).TextContent.Trim();
                    if (featureText.Length > 1)
                    {
                        featureSpecModels.add(specModelIndex, featureText);
                    }
                }
            }
            else
            {
                for (int i = 0; i < submodelList.Length; i++)
                {
                    string   name        = ((Element)submodelList.item(i)).getAttribute("name");
                    NodeList featureList = ((Element)submodelList.item(i)).getElementsByTagName("feature");
                    for (int j = 0; j < featureList.Length; j++)
                    {
                        string featureText = ((Element)featureList.item(j)).TextContent.Trim();
                        if (featureText.Length > 1)
                        {
                            featureSpecModels.add(specModelIndex, name, featureText);
                        }
                    }
                }
            }
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void load(java.net.URL specModelURL, org.maltparser.core.feature.spec.SpecificationModels featureSpecModels) throws org.maltparser.core.exception.MaltChainedException
        public virtual void load(URL specModelURL, SpecificationModels featureSpecModels)
        {
            try
            {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder        db  = dbf.newDocumentBuilder();
                Element root = null;

                root = db.parse(specModelURL.openStream()).DocumentElement;

                if (root == null)
                {
                    throw new FeatureException("The feature specification file '" + specModelURL.File + "' cannot be found. ");
                }

                readFeatureModels(root, featureSpecModels);
            }
            catch (IOException e)
            {
                throw new FeatureException("The feature specification file '" + specModelURL.File + "' cannot be found. ", e);
            }
            catch (SAXParseException e)
            {
                throw new FeatureException("Problem parsing the feature specification XML-file " + specModelURL.File + ". ", e);
            }
            catch (ParserConfigurationException e)
            {
                throw new FeatureException("Problem parsing the feature specification XML-file " + specModelURL.File + ". ", e);
            }
            catch (SAXException e)
            {
                throw new FeatureException("Problem parsing the feature specification XML-file " + specModelURL.File + ". ", e);
            }
        }
Example #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readFeatureModels(org.w3c.dom.Element featuremodels, org.maltparser.core.feature.spec.SpecificationModels featureSpecModels) throws org.maltparser.core.exception.MaltChainedException
        private void readFeatureModels(Element featuremodels, SpecificationModels featureSpecModels)
        {
            NodeList featureModelList = featuremodels.getElementsByTagName("featuremodel");

            for (int i = 0; i < featureModelList.Length; i++)
            {
                readFeatureModel((Element)featureModelList.item(i), featureSpecModels);
            }
        }
Example #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void load(java.net.URL specModelURL, org.maltparser.core.feature.spec.SpecificationModels featureSpecModels) throws org.maltparser.core.exception.MaltChainedException
        public virtual void load(URL specModelURL, SpecificationModels featureSpecModels)
        {
            StreamReader br         = null;
            Pattern      tabPattern = Pattern.compile("\t");

            if (specModelURL == null)
            {
                throw new FeatureException("The feature specification file cannot be found. ");
            }
            try
            {
                br = new StreamReader(specModelURL.openStream());
            }
            catch (IOException e)
            {
                throw new FeatureException("Could not read the feature specification file '" + specModelURL.ToString() + "'. ", e);
            }

            if (br != null)
            {
                int           specModelIndex = featureSpecModels.NextIndex;
                string        fileLine;
                string[]      items;
                StringBuilder featureText    = new StringBuilder();
                string        splitfeats     = "";
                List <string> fileLines      = new List <string>();
                List <string> orderFileLines = new List <string>();
                while (true)
                {
                    try
                    {
                        fileLine = br.ReadLine();
                    }
                    catch (IOException e)
                    {
                        throw new FeatureException("Could not read the feature specification file '" + specModelURL.ToString() + "'. ", e);
                    }
                    if (ReferenceEquals(fileLine, null))
                    {
                        break;
                    }
                    if (fileLine.Length <= 1 && fileLine.Trim().Substring(0, 2).Trim().Equals("--"))
                    {
                        continue;
                    }
                    fileLines.Add(fileLine);
                }
                try
                {
                    br.Close();
                }
                catch (IOException e)
                {
                    throw new FeatureException("Could not close the feature specification file '" + specModelURL.ToString() + "'. ", e);
                }

                for (int j = 0; j < fileLines.Count; j++)
                {
                    orderFileLines.Add(fileLines[j]);
                }

                bool deprel = false;
                for (int j = 0; j < orderFileLines.Count; j++)
                {
                    deprel             = false;
                    featureText.Length = 0;
                    splitfeats         = "";
                    items = tabPattern.split(orderFileLines[j]);
                    if (items.Length < 2)
                    {
                        throw new FeatureException("The feature specification file '" + specModelURL.ToString() + "' must contain at least two columns.");
                    }
                    if (!(columnNameMap.ContainsKey(Enum.Parse(typeof(ColumnNames), items[0].Trim())) || columnNameMap.ContainsValue(items[0].Trim())))
                    {
                        throw new FeatureException("Column one in the feature specification file '" + specModelURL.ToString() + "' contains an unknown value '" + items[0].Trim() + "'. ");
                    }
                    if (items[0].Trim().Equals("DEP", StringComparison.OrdinalIgnoreCase) || items[0].Trim().Equals("DEPREL", StringComparison.OrdinalIgnoreCase))
                    {
                        featureText.Append("OutputColumn(DEPREL, ");
                        deprel = true;
                    }
                    else
                    {
                        if (columnNameMap.ContainsKey(Enum.Parse(typeof(ColumnNames), items[0].Trim())))
                        {
                            featureText.Append("InputColumn(" + columnNameMap[Enum.Parse(typeof(ColumnNames), items[0].Trim())] + ", ");
                        }
                        else if (columnNameMap.ContainsValue(items[0].Trim()))
                        {
                            featureText.Append("InputColumn(" + items[0].Trim() + ", ");
                        }
                        if (items[0].Trim().Equals("FEATS", StringComparison.OrdinalIgnoreCase) && UseSplitFeats)
                        {
                            splitfeats = "Split(";
                        }
                    }
                    if (!(items[1].Trim().Equals("STACK", StringComparison.OrdinalIgnoreCase) || items[1].Trim().Equals("INPUT", StringComparison.OrdinalIgnoreCase) || items[1].Trim().Equals("CONTEXT", StringComparison.OrdinalIgnoreCase)))
                    {
                        throw new FeatureException("Column two in the feature specification file '" + specModelURL.ToString() + "' should be either 'STACK', 'INPUT' or 'CONTEXT' (Covington), not '" + items[1].Trim() + "'. ");
                    }
                    int offset = 0;
                    if (items.Length >= 3)
                    {
                        try
                        {
                            offset = new int?(int.Parse(items[2]));
                        }
                        catch (FormatException e)
                        {
                            throw new FeatureException("The feature specification file '" + specModelURL.ToString() + "' contains a illegal integer value. ", e);
                        }
                    }
                    string functionArg = "";

                    if (items[1].Trim().Equals("CONTEXT", StringComparison.OrdinalIgnoreCase))
                    {
                        if (offset >= 0)
                        {
                            functionArg = dataStructuresMap[Enum.Parse(typeof(DataStructures), "LEFTCONTEXT")] + "[" + offset + "]";
                        }
                        else
                        {
                            functionArg = dataStructuresMap[Enum.Parse(typeof(DataStructures), "RIGHTCONTEXT")] + "[" + Math.Abs(offset + 1) + "]";
                        }
                    }
                    else if (dataStructuresMap.ContainsKey(Enum.Parse(typeof(DataStructures), items[1].Trim())))
                    {
                        if (covington == true)
                        {
                            if (dataStructuresMap[Enum.Parse(typeof(DataStructures), items[1].Trim())].Equals("Stack", StringComparison.OrdinalIgnoreCase))
                            {
                                functionArg = "Left[" + offset + "]";
                            }
                            else
                            {
                                functionArg = "Right[" + offset + "]";
                            }
                        }
                        else
                        {
                            functionArg = dataStructuresMap[Enum.Parse(typeof(DataStructures), items[1].Trim())] + "[" + offset + "]";
                        }
                    }
                    else if (dataStructuresMap.ContainsValue(items[1].Trim()))
                    {
                        if (covington == true)
                        {
                            if (items[1].Trim().Equals("Stack", StringComparison.OrdinalIgnoreCase))
                            {
                                functionArg = "Left[" + offset + "]";
                            }
                            else
                            {
                                functionArg = "Right[" + offset + "]";
                            }
                        }
                        else
                        {
                            functionArg = items[1].Trim() + "[" + offset + "]";
                        }
                    }
                    else
                    {
                        throw new FeatureException("Column two in the feature specification file '" + specModelURL.ToString() + "' should not contain the value '" + items[1].Trim());
                    }

                    int linearOffset = 0;
                    int headOffset   = 0;
                    int depOffset    = 0;
                    int sibOffset    = 0;
                    int suffixLength = 0;
                    if (items.Length >= 4)
                    {
                        linearOffset = new int?(int.Parse(items[3]));
                    }
                    if (items.Length >= 5)
                    {
                        headOffset = new int?(int.Parse(items[4]));
                    }
                    if (items.Length >= 6)
                    {
                        depOffset = new int?(int.Parse(items[5]));
                    }
                    if (items.Length >= 7)
                    {
                        sibOffset = new int?(int.Parse(items[6]));
                    }
                    if (items.Length >= 8)
                    {
                        suffixLength = new int?(int.Parse(items[7]));
                    }
                    if (linearOffset < 0)
                    {
                        linearOffset = Math.Abs(linearOffset);
                        for (int i = 0; i < linearOffset; i++)
                        {
                            functionArg = "pred(" + functionArg + ")";
                        }
                    }
                    else if (linearOffset > 0)
                    {
                        for (int i = 0; i < linearOffset; i++)
                        {
                            functionArg = "succ(" + functionArg + ")";
                        }
                    }
                    if (headOffset >= 0)
                    {
                        for (int i = 0; i < headOffset; i++)
                        {
                            functionArg = "head(" + functionArg + ")";
                        }
                    }
                    else
                    {
                        throw new FeatureException("The feature specification file '" + specModelURL.ToString() + "' should not contain a negative head function value. ");
                    }
                    if (depOffset < 0)
                    {
                        depOffset = Math.Abs(depOffset);
                        for (int i = 0; i < depOffset; i++)
                        {
                            functionArg = "ldep(" + functionArg + ")";
                        }
                    }
                    else if (depOffset > 0)
                    {
                        for (int i = 0; i < depOffset; i++)
                        {
                            functionArg = "rdep(" + functionArg + ")";
                        }
                    }
                    if (sibOffset < 0)
                    {
                        sibOffset = Math.Abs(sibOffset);
                        for (int i = 0; i < sibOffset; i++)
                        {
                            functionArg = "lsib(" + functionArg + ")";
                        }
                    }
                    else if (sibOffset > 0)
                    {
                        for (int i = 0; i < sibOffset; i++)
                        {
                            functionArg = "rsib(" + functionArg + ")";
                        }
                    }

                    if (deprel == true && (pppath == true || pplifted == true || ppcoveredRoot == true))
                    {
                        featureSpecModels.add(specModelIndex, mergePseudoProjColumns(functionArg));
                    }
                    else
                    {
                        if (suffixLength != 0)
                        {
                            featureSpecModels.add(specModelIndex, "Suffix(" + featureText.ToString() + functionArg + ")," + suffixLength + ")");
                        }
                        else if (splitfeats.Equals("Split("))
                        {
                            featureSpecModels.add(specModelIndex, splitfeats + featureText.ToString() + functionArg + "),\\|)");
                        }
                        else
                        {
                            featureSpecModels.add(specModelIndex, featureText.ToString() + functionArg + ")");
                        }
                    }
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public FeatureModelManager(org.maltparser.core.feature.system.FeatureEngine engine) throws org.maltparser.core.exception.MaltChainedException
        public FeatureModelManager(FeatureEngine engine)
        {
            specModels    = new SpecificationModels();
            featureEngine = engine;
        }