Class for deserialized json field semantics. {"Prefix":"s","Entity":"Article","Property":"headline"}
Inheritance: SchemaSemantics
        /// <summary>
        /// Find <see cref="SemanticSchemaField"/> with given semantics.
        /// </summary>
        /// <param name="fieldSemantics">The semantics to check against</param>
        /// <returns>Schema field or one of its embedded fields that match with the given semantics, null if a match cannot be found</returns>
        public SemanticSchemaField FindFieldBySemantics(FieldSemantics fieldSemantics)
        {
            // Perform a breadth-first lookup: first see if any of the top-level fields match.
            SemanticSchemaField matchingTopLevelField = Fields.FirstOrDefault(ssf => ssf.HasSemantics(fieldSemantics));
            if (matchingTopLevelField != null)
            {
                return matchingTopLevelField;
            }

            // If none of the top-level fields match: let each top-level field do a breadth-first lookup of its embedded fields (recursive).
            return Fields.Select(ssf => ssf.FindFieldBySemantics(fieldSemantics)).FirstOrDefault(matchingField => matchingField != null);
        }
Example #2
0
        /// <summary>
        /// Find <see cref="SemanticSchemaField"/> with given semantics.
        /// </summary>
        /// <param name="fieldSemantics">The semantics to check against</param>
        /// <returns>Schema field or one of its embedded fields that match with the given semantics, null if a match cannot be found</returns>
        public SemanticSchemaField FindFieldBySemantics(FieldSemantics fieldSemantics)
        {
            foreach (var field in Fields)
            {
                var matchingField = field.FindFieldBySemantics(fieldSemantics);
                if (matchingField != null)
                {
                    return matchingField;
                }
            }

            return null;
        }
        /// <summary>
        /// Check if current field contains given semantics.
        /// </summary>
        /// <param name="fieldSemantics">The semantics to check against</param>
        /// <returns>True if this field contains given semantics, false otherwise</returns>
        public bool ContainsSemantics(FieldSemantics fieldSemantics)
        {
            foreach (FieldSemantics property in Semantics)
            {
                // TODO add proper Equals implementation in FieldSemantics
                if (property.Property.Equals(fieldSemantics.Property) &&
                    property.Prefix.Equals(fieldSemantics.Prefix) /*&& -- removed as this is breaking on embedded fields where the property.Entity is something like EmbeddedLink
                    property.Entity.Equals(fieldSemantics.Entity)*/)
                {
                    return true;
                }
            }

            return false;
        }
        /// <summary>
        /// Determines whether the specified object is equal to the current <see cref="FieldSemantics"/>.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the specified object is equal to the current one.
        /// </returns>
        /// <param name="obj">The object to compare with the current object. </param>
        public override bool Equals(object obj)
        {
            FieldSemantics other = obj as FieldSemantics;

            return(other != null && base.Equals(other) && Property == other.Property);
        }
        /// <summary>
        /// Find <see cref="SemanticSchemaField"/> with given semantics.
        /// </summary>
        /// <param name="fieldSemantics">The semantics to check against</param>
        /// <returns>This field or one of its embedded fields that match with the given semantics, null if a match cannot be found</returns>
        public SemanticSchemaField FindFieldBySemantics(FieldSemantics fieldSemantics)
        {
            if (ContainsSemantics(fieldSemantics))
            {
                return this;
            }

            foreach (SemanticSchemaField embeddedField in Fields)
            {
                SemanticSchemaField field = embeddedField.FindFieldBySemantics(fieldSemantics);
                if (field != null)
                {
                    return field;
                }
            }
            return null;
        }
 private static IField GetFieldFromSemantics(MappingData mapData, SemanticProperty info)
 {
     KeyValuePair<string, string>? entityData = GetEntityData(info.Prefix, mapData.TargetEntitiesByPrefix, mapData.ParentDefaultPrefix);
     if (entityData != null)
     {
         // determine field semantics
         string vocab = entityData.Value.Key;
         string prefix = SemanticMapping.GetPrefix(vocab, mapData.Localization);
         if (prefix != null && mapData.EntityNames!=null)
         {
             string property = info.PropertyName;
             string entity = mapData.EntityNames[vocab].FirstOrDefault();
             if (entity != null && mapData.SemanticSchema!=null)
             {
                 FieldSemantics fieldSemantics = new FieldSemantics(prefix, entity, property);
                 // locate semantic schema field
                 SemanticSchemaField matchingField = mapData.SemanticSchema.FindFieldBySemantics(fieldSemantics);
                 if (matchingField != null)
                 {
                     return ExtractMatchedField(matchingField, (matchingField.IsMetadata && mapData.Meta!=null) ? mapData.Meta : mapData.Content, mapData.EmbedLevel);
                 }
             }
         }
     }
     return null;
 }
Example #7
0
 /// <summary>
 /// Check if current field has given semantics.
 /// </summary>
 /// <param name="fieldSemantics">The semantics to check against</param>
 /// <returns><c>true</c> if this field has given semantics, <c>false</c> otherwise.</returns>
 public bool HasSemantics(FieldSemantics fieldSemantics) => Semantics.Any(s => s.Equals(fieldSemantics));