Beispiel #1
0
        static void Main(string[] args)
        {
            CmdOptions opts = new CmdOptions();

            if (CommandLine.Parser.Default.ParseArguments(args, opts))
            {
                List <string> files = new List <string>(opts.ExplicitFiles.Select(_ => _.Trim()));
                if (opts.InputDirectory != null)
                {
                    //  Log.WriteLine("Including files from directory {0}", Path.GetFullPath(opts.InputDirectory));
                    files.AddRange(Directory.GetFiles(opts.InputDirectory).Select(_ => _.Trim()));
                }

                Stopwatch timer = Stopwatch.StartNew();

                if (opts.TSL != null)
                {
                    var tslCompiler = new TSLCompiler();
                    opts.TSLAssembly = tslCompiler.Compile(opts.TSL);
                    if (opts.TSLAssembly != null)
                    {
                        Importer.Import(opts.TSLAssembly, files, opts);
                    }
                    else
                    {
                        Log.WriteLine("TSL File Compile Error.");
                    }
                }
                else if (opts.TSLAssembly != null)
                {
                    Importer.Import(opts.TSLAssembly, files, opts);
                }
                else if (opts.GenerateTSL)
                {
                    TSLGenerator.Generate(files, opts);
                }

                timer.Stop();
                Log.WriteLine("Time: {0} seconds.", timer.ElapsedMilliseconds / 1000);
            }
        }
Beispiel #2
0
        public void Scan(string content)
        {
            Triple triple = ParseTriple(content);

            if (triple.Subject == null)
            {
                return;
            }

            var    cellId   = MID2CellId(triple.Subject);
            string type     = GetTypeName(triple.Predicate);
            string property = GetTslName(triple.Predicate);

            int fieldId = TSLGenerator.GetFieldId(property);

            using (var metacell = Global.LocalStorage.UseMetaCell(cellId, Trinity.TSL.Lib.CellAccessOptions.CreateNewOnCellNotFound))
            {
                metacell.TypeId = -1;//mark type id to -1, indicating that this a multi-typed cell TODO constant
                MetaField_Accessor field = metacell.Fields.FirstOrDefault(_ => _.fieldId == fieldId);

                if (field == null)
                {
                    //add new field
                    metacell.Fields.Add(new MetaField
                    {
                        fieldId   = fieldId,
                        fieldType = GetFieldType(ref triple),
                        isList    = false,
                        typeId    = TSLGenerator.GetTypeId(type)
                    });
                }
                else
                {
                    field.isList = true;
                    var newFieldType = GetFieldType(ref triple);
                    field.fieldType = TSLGenerator.UpdateFieldType(field.fieldType, newFieldType);
                }
            }
        }
Beispiel #3
0
        public void Scan(List <string> entity)
        {
            var type_groups = entity.Select(ParseTriple).Where(_ => _.Subject != null).GroupBy(_ => GetTypeName(_.Predicate)).ToList();

            if (type_groups.Count == 0)
            {
                return;
            }
            var cellId = MID2CellId(type_groups[0].First().Subject);

            var metacell = new MetaCell(cellId, Fields: new List <MetaField>());

            metacell.TypeId = -1;//mark type id to -1, indicating that this a multi-typed cell TODO constant
            foreach (var type_group in type_groups)
            {
                string type   = type_group.Key;
                int    typeId = TSLGenerator.GetTypeId(type);

                foreach (var property_instances in type_group.GroupBy(_ => GetTslName(_.Predicate)))
                {
                    string    property  = property_instances.Key;
                    int       fieldId   = TSLGenerator.GetFieldId(property);
                    bool      isList    = property_instances.Count() > 1;
                    FieldType fieldType = property_instances.Aggregate(FieldType.ft_byte, (v, current) =>
                    {
                        var current_ft = GetFieldType(ref current);
                        return(TSLGenerator.UpdateFieldType(v, current_ft));
                    });
                    MetaField field = new MetaField {
                        fieldId = fieldId, fieldType = fieldType, isList = isList, typeId = typeId
                    };
                    metacell.Fields.Add(field);
                }
            }

            Global.LocalStorage.SaveMetaCell(metacell);
        }