//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public DataFormatSpecification loadDataFormat(java.net.URL dataFormatUrl) throws org.maltparser.core.exception.MaltChainedException public virtual DataFormatSpecification loadDataFormat(URL dataFormatUrl) { if (dataFormatUrl == null) { return(null); } DataFormatSpecification dataFormat = fileNameDataFormatSpecs[dataFormatUrl.ToString()]; if (dataFormat == null) { dataFormat = new DataFormatSpecification(); dataFormat.parseDataFormatXMLfile(dataFormatUrl); fileNameDataFormatSpecs[dataFormatUrl.ToString()] = dataFormat; nameDataFormatSpecs[dataFormat.DataFormatName] = dataFormat; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.maltparser.core.helper.URLFinder f = new org.maltparser.core.helper.URLFinder(); UrlFinder f = new UrlFinder(); foreach (Dependency dep in dataFormat.Dependencies) { loadDataFormat(f.FindUrLinJars(dep.UrlString)); } } return(dataFormat); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void load(String urlstring) throws org.maltparser.core.exception.MaltChainedException public virtual void load(string urlstring) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.maltparser.core.helper.URLFinder f = new org.maltparser.core.helper.URLFinder(); UrlFinder f = new UrlFinder(); load(f.FindUrl(urlstring)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void parseHeadRules(String fileName) throws org.maltparser.core.exception.MaltChainedException public virtual void parseHeadRules(string fileName) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.maltparser.core.helper.URLFinder f = new org.maltparser.core.helper.URLFinder(); UrlFinder f = new UrlFinder(); parseHeadRules(f.FindUrl(fileName)); }
static void Check(string input, params string[] expected_matches) { var results = UrlFinder.Search(input).ToArray(); Assert.AreEqual(expected_matches.Length, results.Length); for (int i = 0; i < results.Length && i < expected_matches.Length; ++i) { Assert.AreEqual(expected_matches[i], results[i].Value); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void parseDataFormatXMLfile(String fileName) throws org.maltparser.core.exception.MaltChainedException public virtual void parseDataFormatXMLfile(string fileName) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.maltparser.core.helper.URLFinder f = new org.maltparser.core.helper.URLFinder(); UrlFinder f = new UrlFinder(); URL url = f.FindUrl(fileName); if (url == null) { throw new DataFormatException("The data format specifcation file '" + fileName + "'cannot be found. "); } parseDataFormatXMLfile(url); }
/** * start with "ss://". * Reference code: * https://github.com/shadowsocks/shadowsocks-windows/raw/master/shadowsocks-csharp/Model/Server.cs */ public static ServerProfile ParseLegacyServer(string ssUrl) { var match = UrlFinder.Match(ssUrl); if (!match.Success) { return(null); } ServerProfile serverProfile = new ServerProfile(); var base64 = match.Groups["base64"].Value.TrimEnd('/'); var tag = match.Groups["tag"].Value; if (!string.IsNullOrEmpty(tag)) { serverProfile.vRemarks = HttpUtility.UrlDecode(tag, Encoding.UTF8); } Match details = null; try { details = DetailsParser.Match( Encoding.UTF8.GetString(Convert.FromBase64String(base64.PadRight(base64.Length + (4 - base64.Length % 4) % 4, '=')))); } catch (FormatException) { return(null); } if (!details.Success) { return(null); } serverProfile.vEncrypt = details.Groups["method"].Value; serverProfile.vPassword = details.Groups["password"].Value; serverProfile.vHostIP = details.Groups["hostname"].Value; serverProfile.vPort = int.Parse(details.Groups["port"].Value); serverProfile.SetFriendlyNameDefault(); return(serverProfile); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void initReader(Class syntaxGraphReader, String inputFile, String inputCharSet, String readerOptions, int iterations) throws org.maltparser.core.exception.MaltChainedException public virtual void initReader(Type syntaxGraphReader, string inputFile, string inputCharSet, string readerOptions, int iterations) { try { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.maltparser.core.helper.URLFinder f = new org.maltparser.core.helper.URLFinder(); UrlFinder f = new UrlFinder(); reader = Activator.CreateInstance(syntaxGraphReader); if (ReferenceEquals(inputFile, null) || inputFile.Length == 0 || inputFile.Equals("/dev/stdin")) { reader.open(System.in, inputCharSet); } else if (Directory.Exists(inputFile) || File.Exists(inputFile)) { reader.NIterations = iterations; reader.open(inputFile, inputCharSet); } else { reader.NIterations = iterations; reader.open(f.FindUrl(inputFile), inputCharSet); } reader.DataFormatInstance = inputDataFormatInstance; reader.Options = readerOptions; } catch (InstantiationException e) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new DataFormatException("The data reader '" + syntaxGraphReader.FullName + "' cannot be initialized. ", e); } catch (IllegalAccessException e) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new DataFormatException("The data reader '" + syntaxGraphReader.FullName + "' cannot be initialized. ", e); } }
public Server(string ssUrl) { if (!ssUrl.StartsWith("ss://", StringComparison.OrdinalIgnoreCase)) { throw new Exception("Invalid"); } if (ssUrl.EndsWith("/?outline=1", StringComparison.OrdinalIgnoreCase)) { var outline = OutlineFinder.Match(ssUrl); if (outline.Success) { var base64 = outline.Groups["base64"].Value.TrimEnd('/'); var spl = base64.DeBase64().Split(':'); if (spl.Length == 2) { method = spl[0]; password = spl[1]; server = outline.Groups["hostname"].Value; server_port = int.Parse(outline.Groups["port"].Value); timeout = DefaultServerTimeoutSec; Logging.Info("Parse Outline Server:" + FriendlyName()); return; } } } if (UriFinder.IsMatch(ssUrl)) {//new format Uri parsedUrl; try { parsedUrl = new Uri(ssUrl); } catch (UriFormatException) { throw new Exception("Invalid"); } remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped); server = parsedUrl.GetComponents(UriComponents.Host, UriFormat.Unescaped); server_port = parsedUrl.Port; var rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped); var base64 = rawUserInfo.Replace('-', '+').Replace('_', '/'); // Web-safe base64 to normal base64 string userInfo; try { userInfo = base64.DeBase64(); } catch (FormatException) { throw new Exception("Invalid"); } var userInfoParts = userInfo.Split(new[] { ':' }, 2); if (userInfoParts.Length != 2) { throw new Exception("Invalid"); } method = userInfoParts[0]; password = userInfoParts[1]; var queryParameters = new NameValueCollection(); if (parsedUrl.Query.StartsWith("?")) { var queryString = parsedUrl.Query.Substring(1, parsedUrl.Query.Length - 1); foreach (string element in queryString.Split('&')) { string[] pair = element.Split('='); if (pair.Length == 2) { string name = Uri.UnescapeDataString(pair[0]); string value = Uri.UnescapeDataString(pair[1]); queryParameters.Add(name, value); } } } var pluginParts = (queryParameters["plugin"] ?? "").Split(new[] { ';' }, 2); if (pluginParts.Length > 0) { plugin = pluginParts[0] ?? ""; } if (pluginParts.Length > 1) { plugin_opts = pluginParts[1] ?? ""; } timeout = DefaultServerTimeoutSec; Logging.Info("Parse Server:" + FriendlyName()); } else { var matchOld = UrlFinder.Match(ssUrl); if (matchOld.Success) { var base64 = matchOld.Groups["base64"].Value.TrimEnd('/'); var tag = matchOld.Groups["tag"].Value; if (!string.IsNullOrEmpty(tag)) { remarks = Uri.UnescapeDataString(tag); } Match details; try { details = DetailsParser.Match(base64.DeBase64()); } catch (FormatException) { throw new Exception("Invalid"); } if (!details.Success) { throw new Exception("Invalid"); } method = details.Groups["method"].Value; password = details.Groups["password"].Value; server = details.Groups["hostname"].Value; server_port = int.Parse(details.Groups["port"].Value); timeout = DefaultServerTimeoutSec; Logging.Info("Parse Classic Server:" + FriendlyName()); } else { throw new FormatException("ParseFail:" + ssUrl); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void checkOptionDependency() throws org.maltparser.core.exception.MaltChainedException public virtual void checkOptionDependency() { try { if (configDir.InfoFileWriter != null) { configDir.InfoFileWriter.Write("\nDEPENDENCIES\n"); } // Copy the feature model file into the configuration directory string featureModelFileName = getOptionValue("guide", "features").ToString().Trim(); if (featureModelFileName.Equals("")) { // use default feature model depending on the selected parser algorithm OptionManager.instance().overloadOptionValue(optionContainerIndex, "guide", "features", getOptionValueString("singlemalt", "parsing_algorithm")); featureModelFileName = getOptionValue("guide", "features").ToString().Trim(); /* START: Temp fix during development of new liblinear and libsvm interface */ string learner = getOptionValueString("guide", "learner"); if (!learner.StartsWith("lib", StringComparison.Ordinal)) { learner = "lib" + learner; } /* END: Temp fix during development of new liblinear and libsvm interface */ featureModelFileName = featureModelFileName.Replace("{learner}", learner); featureModelFileName = featureModelFileName.Replace("{dataformat}", getOptionValue("input", "format").ToString().Trim().Replace(".xml", "")); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.maltparser.core.helper.URLFinder f = new org.maltparser.core.helper.URLFinder(); UrlFinder f = new UrlFinder(); featureModelFileName = configDir.copyToConfig(f.FindUrLinJars(featureModelFileName)); } else { featureModelFileName = configDir.copyToConfig(featureModelFileName); } OptionManager.instance().overloadOptionValue(optionContainerIndex, "guide", "features", featureModelFileName); if (configDir.InfoFileWriter != null) { configDir.InfoFileWriter.Write("--guide-features ( -F) " + getOptionValue("guide", "features").ToString() + "\n"); } if (getOptionValue("guide", "data_split_column").ToString().Equals("") && !getOptionValue("guide", "data_split_structure").ToString().Equals("")) { configLogger.warn("Option --guide-data_split_column = '' and --guide-data_split_structure != ''. Option --guide-data_split_structure is overloaded with '', this will cause the parser to induce a single model.\n "); OptionManager.instance().overloadOptionValue(optionContainerIndex, "guide", "data_split_structure", ""); if (configDir.InfoFileWriter != null) { configDir.InfoFileWriter.Write("--guide-data_split_structure ( -s)\n"); } } if (!getOptionValue("guide", "data_split_column").ToString().Equals("") && getOptionValue("guide", "data_split_structure").ToString().Equals("")) { configLogger.warn("Option --guide-data_split_column != '' and --guide-data_split_structure = ''. Option --guide-data_split_column is overloaded with '', this will cause the parser to induce a single model.\n"); OptionManager.instance().overloadOptionValue(optionContainerIndex, "guide", "data_split_column", ""); if (configDir.InfoFileWriter != null) { configDir.InfoFileWriter.Write("--guide-data_split_column ( -d)\n"); } } string decisionSettings = getOptionValue("guide", "decision_settings").ToString().Trim(); string markingStrategy = getOptionValue("pproj", "marking_strategy").ToString().Trim(); string coveredRoot = getOptionValue("pproj", "covered_root").ToString().Trim(); StringBuilder newDecisionSettings = new StringBuilder(); if (ReferenceEquals(decisionSettings, null) || decisionSettings.Length < 1 || decisionSettings.Equals("default")) { decisionSettings = "T.TRANS+A.DEPREL"; } else { decisionSettings = decisionSettings.ToUpper(); } if (markingStrategy.Equals("head", StringComparison.OrdinalIgnoreCase) || markingStrategy.Equals("path", StringComparison.OrdinalIgnoreCase) || markingStrategy.Equals("head+path", StringComparison.OrdinalIgnoreCase)) { if (!Pattern.matches(".*A\\.PPLIFTED.*", decisionSettings)) { newDecisionSettings.Append("+A.PPLIFTED"); } } if (markingStrategy.Equals("path", StringComparison.OrdinalIgnoreCase) || markingStrategy.Equals("head+path", StringComparison.OrdinalIgnoreCase)) { if (!Pattern.matches(".*A\\.PPPATH.*", decisionSettings)) { newDecisionSettings.Append("+A.PPPATH"); } } if (!coveredRoot.Equals("none", StringComparison.OrdinalIgnoreCase) && !Pattern.matches(".*A\\.PPCOVERED.*", decisionSettings)) { newDecisionSettings.Append("+A.PPCOVERED"); } if (!getOptionValue("guide", "decision_settings").ToString().Equals(decisionSettings) || newDecisionSettings.Length > 0) { OptionManager.instance().overloadOptionValue(optionContainerIndex, "guide", "decision_settings", decisionSettings + newDecisionSettings.ToString()); if (configDir.InfoFileWriter != null) { configDir.InfoFileWriter.Write("--guide-decision_settings ( -gds) " + getOptionValue("guide", "decision_settings").ToString() + "\n"); } } if (configDir.InfoFileWriter != null) { configDir.InfoFileWriter.Flush(); } } catch (IOException e) { throw new ConfigurationException("Could not write to the configuration information file. ", e); } }