public static MetaTable MergeTables(MetaTablePropertyAliasList alias, IEnumerable <MetaTable> tables) { var d = tables.First().description; MetaTable output = new MetaTable(d); foreach (MetaTable table in tables) { Dictionary <String, MetaTableProperty> matchedPropertyBySourceName = new Dictionary <string, MetaTableProperty>(); foreach (var property in table.properties.items) { MetaTableProperty matched_property = output.properties.Get(property.PropertyName, alias); if (matched_property == null) { output.properties.Import(property); matched_property = property; } matchedPropertyBySourceName.Add(property.PropertyName, matched_property); } output.entries.ExpandEntries(output.properties); var targetEntries = output.entries.GetEntryDictionary(d.entryIDPropertyName); var sourceEntries = table.entries.GetEntryDictionary(d.entryIDPropertyName); foreach (var pair in sourceEntries) { // targetEntries.entries.CreateEntry() MetaTableEntry entry = null; if (!targetEntries.ContainsKey(pair.Key)) { throw new NotImplementedException(); //entry = output.CreateEntry() //output.entries.Add(entry); } else { entry = targetEntries[pair.Key]; } foreach (var matchedPair in matchedPropertyBySourceName) { var sourceVal = pair.Value.properties[matchedPair.Key]; entry.properties[matchedPair.Value.PropertyName] = sourceVal; } } } return(output); }
public void AcceptEntryProperties(MetaTableEntry entry) { foreach (var ep in EntityClassDefinition.Properties) { if (ep.type.HasFlag(MetaEntityClassPropertyType.value)) { if (entry.HasValueFor(ep)) { SetSetter(ep.PropertyName, entry.GetOutputValue(ep)); } } } }
public Boolean AcceptData(MetaTable table) { var interpretation = table.description.Interpretation; var EntitySelector = table.description.MetaEntitySetterExpression; var EntityClassName = table.description.MetaEntityClassName.or(Settings.RootEntityClassNamepath); MetaEntity selectedEntity = CurrentEntity.SelectTarget(EntitySelector) as MetaEntity; selectedEntity.CheckClassDefinition(Namespaces, EntityClassName); if (selectedEntity.EntityClassDefinition == RootEntityClassSelection.SelectedClass) { interpretation = MetaTableInterpretation.singleEntity; } MetaEntityItemSelection ReflectionSelection = new MetaEntityItemSelection(selectedEntity.EntityClassDefinition); switch (interpretation) { case MetaTableInterpretation.singleEntity: MetaTableEntry firstEntry = table.entries.items.FirstOrDefault(); selectedEntity.AcceptEntryProperties(firstEntry); break; case MetaTableInterpretation.multiEntities: foreach (var entry in table.entries.items) { var subentity = selectedEntity.EntityClassDefinition.CreateEntity(ReflectionSelection.SelectedNamespace, ""); subentity.AcceptEntryProperties(entry); selectedEntity.Items.Add(subentity); } break; default: case MetaTableInterpretation.triplets: return(false); break; } return(true); }
/// <summary> /// Sets the object by entry from MetaTable /// </summary> /// <param name="entry">The entry.</param> /// <param name="input">The input.</param> /// <param name="existing">The existing.</param> /// <param name="OverwriteExisting">if set to <c>true</c> [overwrite existing].</param> /// <returns></returns> public Object SetObjectByMetaEntry(MetaTableEntry entry, MetaTable input, Object existing = null, Boolean OverwriteExisting = true) { if (existing == null) { existing = type.getInstance(null); } object[] o = new object[] { }; foreach (KeyValuePair <MetaTableProperty, PropertyInfo> pair in propertyLinkABs) { MetaTableProperty metaProperty = input.properties.Get(pair.Key.PropertyName); if (metaProperty != null) { Object v = entry.GetOutputValue(metaProperty); SetPropertyValue(metaProperty, pair.Value, v, existing, OverwriteExisting); } } return(existing); }
//public override MetaTableSchema GetTableSchema() //{ // return null; // //throw new NotImplementedException(); //} /// <summary> /// Constructs the specified source table. /// </summary> /// <param name="sourceTable">The source table.</param> /// <param name="task">The task.</param> /// <returns></returns> public override MetaTable Construct(SourceTable sourceTable, TableExtractionTask task) { if (UseUniversalConstructors) { return(base.Construct(sourceTable, task)); } MetaTable table = new MetaTable(GetTableDescription()); var rows = sourceTable.GetContentCells(); //var data = sourceTable.GetContentCells(); Boolean IsMultiEntryList = false; if (sourceTable.Width > 2) { IsMultiEntryList = true; } if (IsMultiEntryList) { table.description.format = MetaTableFormatType.vertical; var entryIDProperty = table.properties.Add("ID"); entryIDProperty.index = EntryID; var EntryPropertyTerm = table.properties.Add("Term"); EntryPropertyTerm.index = PropertyX; var EntryPropertyValue = table.properties.Add("Value"); EntryPropertyValue.index = ValueX; foreach (var row in rows) { table.entries.CreateEntry(row, true); } } else { table.description.format = MetaTableFormatType.horizontal; Dictionary <String, MetaTableProperty> propDict = new Dictionary <string, MetaTableProperty>(); List <String> propertyValues = new List <string>(); foreach (var row in rows) { String propertyName = row[PropertyX].Value; String propertyValue = row[ValueX].Value; propertyValues.Add(propertyValue); var vInfo = sourceContentAnalysis.DetermineContentType(propertyValue, true); var metaProperty = table.properties.Add(propertyName); metaProperty.ContentType = vInfo.type; propDict.Add(propertyName, metaProperty); RefinedPropertyStats pStats = new RefinedPropertyStats(); pStats.Assign(vInfo); pStats.Compute(); pStats.Deploy(metaProperty); } MetaTableEntry entry = table.entries.CreateEntry(propertyValues, true); } return(table); }
/// <summary> /// Sets the object by meta entry. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entry">The entry.</param> /// <param name="existing">The existing.</param> /// <param name="OverwriteExisting">if set to <c>true</c> [overwrite existing].</param> /// <returns></returns> public T SetObjectByMetaEntry <T>(MetaTableEntry entry, T existing = null, Boolean OverwriteExisting = true) where T : class, new() { return(SetObjectByMetaEntry(entry, existing as T, true)); }