/// <summary>
 /// Serializes the <see cref="Extractors"/> state property to its XML serialization format.
 /// </summary>
 /// <param name="writer">
 /// The <see cref="XmlWriter"/> to serialize the <see cref="Extractors"/> state property to.
 /// </param>
 public void WriteXml(XmlWriter writer)
 {
     if (Extractors.Any())
     {
         WriteXmlProperties(writer);
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.LiterateConsole()
                         .CreateLogger();
            L = Log.ForContext <Program>();

            var result = Parser.Default.ParseArguments <ExtractOptions, TransformOptions>(args)
                         .WithNotParsed((IEnumerable <Error> errors) =>
            {
                Exit(ExitResult.INVALID_OPTIONS);
            })
                         .WithParsed((ExtractOptions o) =>
            {
                if (Extractors.Contains(o.Extractor))
                {
                    ExtractOptions = o;
                    Extract();
                }
                else
                {
                    L.Error("The current extractors are: {extractors}.", Extractors);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
            });
        }
 /// <summary>
 /// Serializes the <see cref="Extractors"/> state property to its XML serialization format.
 /// </summary>
 /// <param name="writer">
 /// The <see cref="XmlWriter"/> to serialize the <see cref="Extractors"/> state property to.
 /// </param>
 public void WriteXml(XmlWriter writer)
 {
     if (Extractors.Any())
     {
         WriteXmlProperties(writer ?? throw new ArgumentNullException(nameof(writer)));
     }
 }
示例#4
0
        internal IEnumerable <KeyValuePair <string, string> > ToKeyValuePairs()
        {
            var output = new List <KeyValuePair <string, string> >();

            if (!string.IsNullOrWhiteSpace(Text))
            {
                output.Add("text", Text);
            }
            if (!string.IsNullOrWhiteSpace(Url))
            {
                output.Add("url", Url);
            }
            output.Add("extractors", Extractors.ToString().Replace(" ", "").ToLowerInvariant());
            if (!string.IsNullOrWhiteSpace(Rules))
            {
                output.Add("rules", Rules);
            }
            if (!string.IsNullOrWhiteSpace(LanguageOverride))
            {
                output.Add("languageOverride", LanguageOverride);
            }
            if (!string.IsNullOrWhiteSpace(Classifiers))
            {
                output.Add("classifiers", Classifiers);
            }

            output.AddRange(Entities.ToKeyValuePairs());
            output.AddRange(Cleanup.ToKeyValuePairs());
            output.AddRange(Download.ToKeyValuePairs());

            return(output);
        }
示例#5
0
        public IPackageExtractor GetExtractor(string packageFile)
        {
            if (string.IsNullOrEmpty(Path.GetExtension(packageFile)))
            {
                throw new FileFormatException("Package is missing file extension. This is needed to select the correct extraction algorithm.");
            }

            var extractor = ExtensionSuffix(packageFile);

            if (extractor != null)
            {
                return(extractor);
            }


            extractor = ExtensionWithHashSuffix(packageFile);
            if (extractor != null)
            {
                return(extractor);
            }

            var extensionMatch = Regex.Match(Path.GetExtension(packageFile), ExtensionRegex);

            throw new FileFormatException(supportLinkGenerator.GenerateSupportMessage(
                                              string.Format(
                                                  "This step supports packages with the following extenions: {0}.\n" +
                                                  "The supplied package has the extension \"{1}\" which is not supported.",
                                                  Extractors.SelectMany(e => e.Extensions)
                                                  .Distinct()
                                                  .Aggregate((result, e) => result + ", " + e),
                                                  extensionMatch.Success ? extensionMatch.Groups[1].Value : Path.GetExtension(packageFile)),
                                              "JAVA-DEPLOY-ERROR-0001"));
        }
示例#6
0
            public override Header Create(CharSeeker dataSeeker, Configuration config, IdType idType, Groups groups)
            {
                try
                {
                    Mark       mark       = new Mark();
                    Extractors extractors = new Extractors(config.arrayDelimiter(), config.emptyQuotedStringsAsNull(), config.trimStrings(), DefaultTimeZone);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.csv.reader.Extractor<?> idExtractor = idType.extractor(extractors);
                    Extractor <object> idExtractor = idType.extractor(extractors);
                    int delimiter = config.delimiter();
                    IList <Header.Entry> columns = new List <Header.Entry>();
                    for (int i = 0; !mark.EndOfLine && dataSeeker.Seek(mark, delimiter); i++)
                    {
                        string          entryString = dataSeeker.TryExtract(mark, extractors.String()) ? extractors.String().value() : null;
                        HeaderEntrySpec spec        = new HeaderEntrySpec(entryString);

                        if ((string.ReferenceEquals(spec.Name, null) && string.ReferenceEquals(spec.Type, null)) || (!string.ReferenceEquals(spec.Type, null) && spec.Type.Equals(Type.Ignore.name())))
                        {
                            columns.Add(new Header.Entry(null, Type.Ignore, [email protected]_Fields.Global, null, null));
                        }
                        else
                        {
                            Group group = CreateGroups ? groups.GetOrCreate(spec.GroupName) : groups.Get(spec.GroupName);
                            columns.Add(Entry(i, spec.Name, spec.Type, group, extractors, idExtractor));
                        }
                    }
                    Entry[] entries = columns.ToArray();
                    ValidateHeader(entries);
                    return(new Header(entries));
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            }
示例#7
0
        private void EditExtractor(object obj)
        {
            var extractor = Extractors.ElementAt(SelectedIndex);

            if (extractor != null)
            {
                editExtractorService.Edit(extractor);
            }
        }
示例#8
0
        public static Header BareboneNodeHeader(string idKey, IdType idType, Extractors extractors, params Header.Entry[] additionalEntries)
        {
            IList <Header.Entry> entries = new List <Header.Entry>();

            entries.Add(new Header.Entry(idKey, Type.ID, null, idType.extractor(extractors)));
            entries.Add(new Header.Entry(null, Type.LABEL, null, extractors.StringArray()));
            ((IList <Header.Entry>)entries).AddRange(asList(additionalEntries));
            return(new Header(entries.ToArray()));
        }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultFeatureExtractor"/> class.
 /// </summary>
 /// <param name="summarizers">The summarizers.</param>
 public DefaultFeatureExtractor(IEnumerable <IFeatureExtractorLanguage> summarizers)
 {
     Extractors = summarizers.Where(x => x.GetType().Assembly != typeof(DefaultFeatureExtractor).Assembly).ToDictionary(x => x.Name);
     foreach (var Extractor in summarizers.Where(x => x.GetType().Assembly == typeof(DefaultFeatureExtractor).Assembly &&
                                                 !Extractors.ContainsKey(x.Name)))
     {
         Extractors.Add(Extractor.Name, Extractor);
     }
 }
示例#10
0
        public override bool TryConvert(ConvertBinder binder, out object result)
        {
            if (!Extractors.TryGetValue(binder.Type, out var extract) || !extract(Element, out result))
            {
                throw new FormatException($"Unable to convert json value {Element.GetRawText()} to {binder.Type.Name}");
            }

            return(true);
        }
        private void CreateCSharpHeadNode(SyntaxNode root)
        {
            var    nodeType = TypeConversion.FromRoslynKind(root.Kind());
            string name     = Extractors.ExtractName(root);

            Head = new CSharpNode(name, nodeType)
            {
                Visibility = Configuration.Visibility
            };
        }
示例#12
0
        public static Header BareboneRelationshipHeader(IdType idType, Extractors extractors, params Header.Entry[] additionalEntries)
        {
            IList <Header.Entry> entries = new List <Header.Entry>();

            entries.Add(new Header.Entry(null, Type.START_ID, null, idType.extractor(extractors)));
            entries.Add(new Header.Entry(null, Type.END_ID, null, idType.extractor(extractors)));
            entries.Add(new Header.Entry(null, Type.TYPE, null, extractors.String()));
            ((IList <Header.Entry>)entries).AddRange(asList(additionalEntries));
            return(new Header(entries.ToArray()));
        }
        public async Task <Uri> ExtractMedia(string originalUrl)
        {
            var extractor = Extractors.FirstOrDefault(e => e.CanExtract(originalUrl));

            if (extractor == null)
            {
                return(null);
            }

            return(await extractor.GetMediaUrl(originalUrl));
        }
示例#14
0
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: private static org.neo4j.csv.reader.Extractor<?> parsePropertyType(String typeSpec, org.neo4j.csv.reader.Extractors extractors)
        private static Extractor <object> ParsePropertyType(string typeSpec, Extractors extractors)
        {
            try
            {
                return(extractors.ValueOf(typeSpec));
            }
            catch (System.ArgumentException e)
            {
                throw new HeaderException("Unable to parse header", e);
            }
        }
示例#15
0
        private static Header ParseRelationshipHeader(Args args, IdType idType, Extractors extractors, Groups groups)
        {
            string definition = args.Get("relationship-header", null);

            if (string.ReferenceEquals(definition, null))
            {
                return(DataGeneratorInput.bareboneRelationshipHeader(idType, extractors));
            }

            Configuration config = Configuration.COMMAS;

            return(DataFactories.defaultFormatRelationshipFileHeader().create(Seeker(definition, config), config, idType, groups));
        }
示例#16
0
        /// <summary>
        /// The constructor takes the Extractor context for recursion.
        /// </summary>
        /// <param name="context">The Extractor context.</param>
        public Extractor(Extractors type)
        {
            // poor man's type resolving
            switch (type)
            {
            case Extractors.vhdx:
                mExtractor = new SharpExtractor.VhxdExtractor();
                break;

            default:
                throw new NotImplementedException($"{type} extractor not implemented");
                break;
            }
        }
示例#17
0
        IPackageExtractor ReportInvalidExtension(string packageFile)
        {
            var extensionMatch = Regex.Match(Path.GetExtension(packageFile), ExtensionRegex);

            throw new FileFormatException(supportLinkGenerator.GenerateSupportMessage(
                string.Format(
                    "This step supports packages with the following extenions: {0}.\n" +
                    "The supplied package has the extension \"{1}\" which is not supported.",
                    Extractors.SelectMany(e => e.Extensions)
                        .Distinct()
                        .Aggregate((result, e) => result + ", " + e),
                    extensionMatch.Success ? extensionMatch.Groups[1].Value : Path.GetExtension(packageFile)),
                "JAVA-DEPLOY-ERROR-0001"));
        }
        private SyntaxNode GetDeclarationNode(SyntaxNode namespaceNode)
        {
            SyntaxNode classOrInterface = namespaceNode.ChildNodes().FirstOrDefault(node => node.Kind() == SyntaxKind.ClassDeclaration);

            if (classOrInterface == null)
            {
                throw new FileLoadException("Implementation not found");
            }

            bool isAuthorized = GetConstraintAuthorization(classOrInterface);

            if (!isAuthorized)
            {
                throw new UnauthorizedAccessException(
                          $"Class {Extractors.ExtractName(classOrInterface)} do not respect the Attribute constraint {Configuration.AttributeNameConstraint}");
            }

            classOrInterface = classOrInterface ?? namespaceNode.ChildNodes().FirstOrDefault(node => node.Kind() == SyntaxKind.InterfaceDeclaration);

            return(classOrInterface);
        }
        private void InsertNodeInTree(SyntaxNode node)
        {
            SyntaxKind  topLevelKind = node.Kind();
            bool        isReadonly   = false;
            string      name         = "";
            TypeWrapper type         = new TypeWrapper();

            SyntaxNode[] children = node.ChildNodes().ToArray();
            if (children.Length < 1)
            {
                return;
            }

            switch (topLevelKind)
            {
            case SyntaxKind.PropertyDeclaration:
                type       = Extractors.ExtractTypesFromProperty(GetPropertyTypeNode(node));
                name       = Extractors.ExtractName(node);
                isReadonly = Extractors.IsReadOnly(node);
                break;

            case SyntaxKind.FieldDeclaration:
                SyntaxNode firstChild = children.First();
                type = Extractors.ExtractTypesFromField(firstChild);
                name = Extractors.ExtractName(firstChild);
                break;

            case SyntaxKind.MethodDeclaration:
                /*TODO: Method, can have multiple return/parameters type. Handle that when needed*/
                break;
            }

            var csharpNode = new CSharpNode(name, TypeConversion.FromRoslynKind(topLevelKind))
            {
                Type       = type,
                IsReadOnly = isReadonly
            };

            Head.Children.Add(csharpNode);
        }
示例#20
0
 public void AddExtractor(IMediaExtractor extractor)
 {
     Extractors.Add(extractor);
 }
示例#21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void main(String[] arguments) throws java.io.IOException
        public static void Main(string[] arguments)
        {
            Args          args                  = Args.parse(arguments);
            long          nodeCount             = Settings.parseLongWithUnit(args.Get("nodes", null));
            long          relationshipCount     = Settings.parseLongWithUnit(args.Get("relationships", null));
            int           labelCount            = args.GetNumber("labels", 4).intValue();
            int           relationshipTypeCount = args.GetNumber("relationship-types", 4).intValue();
            File          dir        = new File(args.Get(ImportTool.Options.StoreDir.key()));
            long          randomSeed = args.GetNumber("random-seed", currentTimeMillis()).longValue();
            Configuration config     = Configuration.COMMAS;

            Extractors extractors = new Extractors(config.ArrayDelimiter());
            IdType     idType     = IdType.valueOf(args.Get("id-type", IdType.INTEGER.name()));

            Groups groups             = new Groups();
            Header nodeHeader         = ParseNodeHeader(args, idType, extractors, groups);
            Header relationshipHeader = ParseRelationshipHeader(args, idType, extractors, groups);

            Config dbConfig;
            string dbConfigFileName = args.Get(ImportTool.Options.DatabaseConfig.key(), null);

            if (!string.ReferenceEquals(dbConfigFileName, null))
            {
                dbConfig = (new Config.Builder()).withFile(new File(dbConfigFileName)).build();
            }
            else
            {
                dbConfig = Config.defaults();
            }

            bool highIo = args.GetBoolean(ImportTool.Options.HighIo.key());

            LogProvider logging         = NullLogProvider.Instance;
            long        pageCacheMemory = args.GetNumber("pagecache-memory", [email protected]_Fields.MaxPageCacheMemory).longValue();

            [email protected] importConfig = new ConfigurationAnonymousInnerClass(args, highIo, pageCacheMemory);

            float factorBadNodeData         = args.GetNumber("factor-bad-node-data", 0).floatValue();
            float factorBadRelationshipData = args.GetNumber("factor-bad-relationship-data", 0).floatValue();

            Input input = new DataGeneratorInput(nodeCount, relationshipCount, idType, Collector.EMPTY, randomSeed, 0, nodeHeader, relationshipHeader, labelCount, relationshipTypeCount, factorBadNodeData, factorBadRelationshipData);

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), Lifespan life = new Lifespan())
            {
                BatchImporter consumer;
                if (args.GetBoolean("to-csv"))
                {
                    consumer = new CsvOutput(dir, nodeHeader, relationshipHeader, config);
                }
                else
                {
                    Console.WriteLine("Seed " + randomSeed);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.scheduler.JobScheduler jobScheduler = life.add(createScheduler());
                    JobScheduler jobScheduler = life.Add(createScheduler());
                    consumer = BatchImporterFactory.withHighestPriority().instantiate(DatabaseLayout.of(dir), fileSystem, null, importConfig, new SimpleLogService(logging, logging), defaultVisible(jobScheduler), EMPTY, dbConfig, RecordFormatSelector.selectForConfig(dbConfig, logging), NO_MONITOR, jobScheduler);
                    ImportTool.PrintOverview(dir, Collections.emptyList(), Collections.emptyList(), importConfig, System.out);
                }
                consumer.DoImport(input);
            }
        }
示例#22
0
        private void RemoveExtractor(object obj)
        {
            var extractor = Extractors.ElementAt(SelectedIndex);

            removeExtractorService.Remove(extractor);
        }
示例#23
0
        public Uri ExtractMedia(string originalUrl)
        {
            var extractor = Extractors.FirstOrDefault(e => e.CanExtract(originalUrl));

            return(extractor?.GetMediaUrl(originalUrl));
        }
示例#24
0
 public bool IsFiltered(ILogEntry entry)
 {
     return(Extractors.Any(filter => filter.Enabled && filter.IsMatch(entry)) ||
            SearchExtractors.Any(filter => filter.Enabled && filter.IsMatch(entry)));
 }
示例#25
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: boolean next(org.neo4j.unsafe.impl.batchimport.input.InputEntityVisitor visitor) throws java.io.IOException
        internal virtual bool Next(InputEntityVisitor visitor)
        {
            _lineNumber++;
            int   i     = 0;
            Entry entry = null;

            Entry[] entries = _header.entries();
            try
            {
                bool doContinue = true;
                for (i = 0; i < entries.Length && doContinue; i++)
                {
                    entry = entries[i];
                    if (!_seeker.seek(_mark, _delimiter))
                    {
                        if (i > 0)
                        {
                            throw new UnexpectedEndOfInputException("Near " + _mark);
                        }
                        // We're just at the end
                        return(false);
                    }

                    switch (entry.Type())
                    {
                    case ID:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            switch (_idType.innerEnumValue)
                            {
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.STRING:
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.INTEGER:
                                object idValue = entry.Extractor().value();
                                doContinue = visitor.Id(idValue, entry.Group());
                                if (!string.ReferenceEquals(entry.Name(), null))
                                {
                                    doContinue = visitor.Property(entry.Name(), idValue);
                                }
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.ACTUAL:
                                doContinue = visitor.Id(((Extractors.LongExtractor)entry.Extractor()).longValue());
                                break;

                            default:
                                throw new System.ArgumentException(_idType.name());
                            }
                        }
                        break;

                    case START_ID:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            switch (_idType.innerEnumValue)
                            {
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.STRING:
                                doContinue = visitor.StartId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.INTEGER:
                                doContinue = visitor.StartId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.ACTUAL:
                                doContinue = visitor.StartId(((Extractors.LongExtractor)entry.Extractor()).longValue());
                                break;

                            default:
                                throw new System.ArgumentException(_idType.name());
                            }
                        }
                        break;

                    case END_ID:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            switch (_idType.innerEnumValue)
                            {
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.STRING:
                                doContinue = visitor.EndId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.INTEGER:
                                doContinue = visitor.EndId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.ACTUAL:
                                doContinue = visitor.EndId(((Extractors.LongExtractor)entry.Extractor()).longValue());
                                break;

                            default:
                                throw new System.ArgumentException(_idType.name());
                            }
                        }
                        break;

                    case TYPE:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            doContinue = visitor.Type(( string )entry.Extractor().value());
                        }
                        break;

                    case PROPERTY:
                        if (_seeker.tryExtract(_mark, entry.Extractor(), entry.OptionalParameter()))
                        {
                            // TODO since PropertyStore#encodeValue takes Object there's no point splitting up
                            // into different primitive types
                            object value = entry.Extractor().value();
                            if (!IsEmptyArray(value))
                            {
                                doContinue = visitor.Property(entry.Name(), value);
                            }
                        }
                        break;

                    case LABEL:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            object labelsValue = entry.Extractor().value();
                            if (labelsValue.GetType().IsArray)
                            {
                                doContinue = visitor.Labels(( string[] )labelsValue);
                            }
                            else
                            {
                                doContinue = visitor.Labels(new string[] { ( string )labelsValue });
                            }
                        }
                        break;

                    case IGNORE:
                        break;

                    default:
                        throw new System.ArgumentException(entry.Type().ToString());
                    }

                    if (_mark.EndOfLine)
                    {
                        // We're at the end of the line, break and return an entity with what we have.
                        break;
                    }
                }

                while (!_mark.EndOfLine)
                {
                    _seeker.seek(_mark, _delimiter);
                    if (doContinue)
                    {
                        _seeker.tryExtract(_mark, _stringExtractor, entry.OptionalParameter());
                        _badCollector.collectExtraColumns(_seeker.sourceDescription(), _lineNumber, _stringExtractor.value());
                    }
                }
                visitor.EndOfEntity();
                return(true);
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final RuntimeException e)
            catch (Exception e)
            {
                string stringValue = null;
                try
                {
                    Extractors extractors = new Extractors('?');
                    if (_seeker.tryExtract(_mark, extractors.String(), entry.OptionalParameter()))
                    {
                        stringValue = extractors.String().value();
                    }
                }
                catch (Exception)
                {                         // OK
                }

                string message = format("ERROR in input" + "%n  data source: %s" + "%n  in field: %s" + "%n  for header: %s" + "%n  raw field value: %s" + "%n  original error: %s", _seeker, entry + ":" + (i + 1), _header, !string.ReferenceEquals(stringValue, null) ? stringValue : "??", e.Message);

                if (e is InputException)
                {
                    throw Exceptions.withMessage(e, message);
                }
                throw new InputException(message, e);
            }
        }
示例#26
0
        static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.LiterateConsole()
                         .WriteTo.RollingFile(Path.Combine("logs", "CWEBot") + "-{Date}.log")
                         .CreateLogger();
            L = Log.ForContext <Program>();
            var result = Parser.Default.ParseArguments <ExtractOptions, TransformOptions>(args)
                         .WithNotParsed((IEnumerable <Error> errors) =>
            {
                Exit(ExitResult.INVALID_OPTIONS);
            })
                         .WithParsed((ExtractOptions o) =>
            {
                if (Extractors.Contains(o.Extractor))
                {
                    ExtractOptions = o;
                    Extract();
                    Exit(ExitResult.SUCCESS);
                }
                else
                {
                    L.Error("The current extractors are: {extractors}.", Extractors);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
            })
                         .WithParsed((TransformOptions o) =>
            {
                TransformOptions = o;
                if (!File.Exists(TransformOptions.InputFile))
                {
                    L.Error("The input file {0} for transform does not exist.", TransformOptions.InputFile);
                    Exit(ExitResult.INPUT_FILE_ERROR);
                }
                else
                {
                    InputFile = new FileInfo(TransformOptions.InputFile);
                    L.Information("Using input file {file} or transform.", TransformOptions.InputFile);
                }

                TrainingOutputFile = new FileInfo(TransformOptions.OutputFile + ".training.tsv");
                if (TrainingOutputFile.Exists)
                {
                    if (!TransformOptions.OverwriteOutputFile)
                    {
                        L.Error("The training output file {0} exists. Use the --overwrite flag to overwrite an existing file.", TrainingOutputFile.FullName);
                        Exit(ExitResult.OUTPUT_FILE_EXISTS);
                    }
                    else
                    {
                        L.Information("Existing training output file {0} will be overwritten.", TrainingOutputFile.FullName);
                    }
                }

                TestOutputFile = new FileInfo(TransformOptions.OutputFile + ".test.tsv");
                if (TrainingOutputFile.Exists)
                {
                    if (!TransformOptions.OverwriteOutputFile)
                    {
                        L.Error("The test output file {0} exists. Use the --overwrite flag to overwrite an existing file.", TestOutputFile.FullName);
                        Exit(ExitResult.OUTPUT_FILE_EXISTS);
                    }
                    else
                    {
                        L.Information("Existing test output file {0} will be overwritten.", TestOutputFile.FullName);
                    }
                }

                TargetOutputFile = new FileInfo(TransformOptions.OutputFile + ".target.tsv");
                if (TargetOutputFile.Exists)
                {
                    if (!TransformOptions.OverwriteOutputFile)
                    {
                        L.Error("The target output file {0} exists. Use the --overwrite flag to overwrite an existing file.", TargetOutputFile.FullName);
                        Exit(ExitResult.OUTPUT_FILE_EXISTS);
                    }
                    else
                    {
                        L.Information("Existing target dataset file {0} will be overwritten.", TargetOutputFile.FullName);
                    }
                }
                Dictionary <string, object> options = new Dictionary <string, object>();
                if (TransformOptions.WithDescription)
                {
                    options.Add("WithDescription", true);
                }
                if (TransformOptions.VulnerabilitiesLimit > 0)
                {
                    options.Add("VulnerabilitiesLimit", TransformOptions.VulnerabilitiesLimit);
                }
                if (TransformOptions.Split != 8)
                {
                    options.Add("Split", TransformOptions.Split);
                }
                TransformStage transform = new TransformStage(InputFile, TrainingOutputFile, TestOutputFile, TargetOutputFile, options.Count == 0 ? null : options);
                if (!transform.CreateModelDataset())
                {
                    Exit(ExitResult.ERROR_TRANSFORMING_DATA);
                }
                else
                {
                    Exit(ExitResult.SUCCESS);
                }
            });

            return(0);
        }
 public bool CanExtract(string url)
 {
     return(Extractors.Any(e => e.CanExtract(url)));
 }
示例#28
0
        public IPackageExtractor GetExtractor(string packageFile)
        {
            var extension = Path.GetExtension(packageFile);

            if (string.IsNullOrEmpty(extension))
            {
                throw new FileFormatException("Package is missing file extension. This is needed to select the correct extraction algorithm.");
            }

            var file = PackageName.FromFile(packageFile);

            if (!Extensions.Contains(file.Extension))
            {
                throw new FileFormatException($"Unsupported file extension `{extension}`");
            }

            var extractor = FindByExtension(file);

            if (extractor != null)
            {
                return(extractor);
            }

            throw new FileFormatException(supportLinkGenerator.GenerateSupportMessage(
                                              $"This step supports packages with the following extensions: {Extractors.SelectMany(e => e.Extensions).Distinct().Aggregate((result, e) => result + ", " + e)}.\n" +
                                              $"The supplied package has the extension \"{file.Extension}\" which is not supported.",
                                              "JAVA-DEPLOY-ERROR-0001"));
        }
示例#29
0
 public static Header BareboneNodeHeader(IdType idType, Extractors extractors)
 {
     return(BareboneNodeHeader(null, idType, extractors));
 }
示例#30
0
 public static Header SillyNodeHeader(IdType idType, Extractors extractors)
 {
     return(new Header(new Header.Entry(null, Type.ID, null, idType.extractor(extractors)), new Header.Entry("name", Type.PROPERTY, null, extractors.String()), new Header.Entry("age", Type.PROPERTY, null, extractors.Int_()), new Header.Entry("something", Type.PROPERTY, null, extractors.String()), new Header.Entry(null, Type.LABEL, null, extractors.StringArray())));
 }