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); } } }
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); }