protected new void NetworksWithLocationsToTsv(WhoisParser parser, string inputFilePath, string outputFilePath) { var outputFolderPath = Path.GetDirectoryName(outputFilePath); if (!Directory.Exists(outputFolderPath)) { Directory.CreateDirectory(outputFolderPath); } var locationExtraction = new NetworkLocationExtraction(parser); using (var outputFile = new StreamWriter(outputFilePath)) { foreach (var network in locationExtraction.ExtractNetworks(new List <string>() { inputFilePath })) { if (network.Id != null) { if (network.Location != null && network.Location.AddressSeemsValid()) { var networkTsv = network.ToLocationTsv(); outputFile.WriteLine(networkTsv); } else if (network.Description != null) { var networkTsv = network.ToDescriptionTsv(); outputFile.WriteLine(networkTsv); } } //// TODO: Else log } } }
public void NetworksWithLocationsToTsv(string inputFolderPath, string outputFilePath) { var outputFolderPath = Path.GetDirectoryName(outputFilePath); if (!Directory.Exists(outputFolderPath)) { Directory.CreateDirectory(outputFolderPath); } var parser = new WhoisParser(new SectionTokenizer(), new SectionParser()); var locationExtraction = new NetworkLocationExtraction(parser); using (var outputFile = new StreamWriter(outputFilePath)) { foreach (var inputFilePath in Directory.GetFiles(inputFolderPath)) { foreach (var network in locationExtraction.ExtractNetworksWithLocations(inputFilePath, inputFilePath)) { if (network.Id != null) { var networkTsv = network.ToLocationTsv(); outputFile.WriteLine(networkTsv); } //// TODO: else log } } } }
protected void NetworksLocationPropertyCountsToTsv(WhoisParser parser, string inputFilePath, string propertyName, string outputFilePath) { var outputFolderPath = Path.GetDirectoryName(outputFilePath); if (!Directory.Exists(outputFolderPath)) { Directory.CreateDirectory(outputFolderPath); } var locationExtraction = new NetworkLocationExtraction(parser); var stringsCount = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); var normalizedLocationType = typeof(NormalizedLocation); var properties = normalizedLocationType.GetProperties(BindingFlags.Public | BindingFlags.Instance); PropertyInfo targetProperty = null; foreach (var property in properties) { if (property.Name == propertyName) { targetProperty = property; } } if (targetProperty == null) { throw new ArgumentNullException("targetProperty"); } foreach (var network in locationExtraction.ExtractNetworksWithLocations(inputFilePath, inputFilePath)) { if (network.Id != null) { var rawPropertyValue = targetProperty.GetValue(network.Location); if (rawPropertyValue != null) { var value = (string)rawPropertyValue; int currentCount; if (!stringsCount.TryGetValue(value, out currentCount)) { currentCount = 0; } currentCount++; stringsCount[value] = currentCount; } } //// TODO: Else log } using (var outputFile = new StreamWriter(outputFilePath)) { foreach (var entry in stringsCount) { // No need to sanitize entry.Value since it's a number outputFile.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}", TsvUtils.ReplaceAndTrimIllegalCharacters(entry.Key, removeDoubleQuotes: true), entry.Value)); } } }