public Dictionary <string, string> Format(JToken item, int depth) { if (depth > MaxDepth || item == null) { return(new Dictionary <string, string>()); } var obj = item as JObject; if (obj == null) { return(new Dictionary <string, string>() { { string.Empty, string.Empty } }); } var result = new Dictionary <string, string>(); foreach (var prop in obj.Properties()) { try { var val = prop.Value; if (val == null) { continue; } var formatter = Formatters.GetFormatter(val.Type); if (formatter == null) { continue; } var propValue = formatter.Format(val, depth + 1); ResultMerger.Merge(result, prop.Name, propValue); } catch { } // swallow exception } return(result); }
public Dictionary <string, string> Format(JToken item, int depth) { if (depth > MaxDepth || item == null) { return(new Dictionary <string, string>()); } var arr = item as JArray; if (arr == null || arr.Count < 1) { return(new Dictionary <string, string>() { { string.Empty, string.Empty } }); } var result = new Dictionary <string, string>(); var elementValues = new List <Dictionary <string, string> >(); for (int i = 0; i < arr.Count; i++) { JToken valAtIndex = arr[i]; try { var val = arr[i]; if (val == null) { continue; } var formatter = Formatters.GetFormatter(val.Type); if (formatter == null) { continue; } var propValue = formatter.Format(val, depth + 1); elementValues.Add(propValue); } catch { } // swallow exception } // if all elements are single values we just concatenate them in a delimited list // otherwise, make the separate keys var isValueArray = elementValues.All(val => val.Count == 1); if (isValueArray) { result[string.Empty] = string.Join(FieldContentDelimiter, elementValues.Select(x => x[string.Empty])); return(result); } else { for (var i = 0; i < elementValues.Count; i++) { ResultMerger.Merge(result, $"_{i}", elementValues[i]); } } return(result); }
private IEnumerator ExecuteMultiQuery(SimilarQuery query, CategoryRatio ratio, string guid = null) { // === SIMILAR === // Initial SimilarQuery yield return(similarRequest = CineastUtils.BuildSimilarRequest(CineastUtils.Configuration.FindSimilarSegmentsUrl(), query)); // Parse response earlyBreak = !Parse(similarRequest.text, out similarResult); yield return(similarResult); if (earlyBreak) { yield break; } // Check if empty if (similarResult.IsEmpty()) { earlyBreak = true; yield break; // Stop and } ContentObject[] tempResult = CineastUtils.ExtractContentObjects(similarResult); if (ratio != null && similarResult.results.Length > 1) { ResultMerger merger = new ResultMerger(); tempResult = merger.Merge(similarResult.results, ratio) .ToArray(); } // === SEGMENTS === // segments yield return(segmentRequest = CineastUtils.BuildSegmentRequest(CineastUtils.Configuration.FindSegmentsByIdUrl(), CineastUtils.ExtractIdArray(tempResult))); // parse response earlyBreak = !Parse(segmentRequest.text, out segmentResult); yield return(segmentResult); if (earlyBreak) { yield break; } // === METAS === yield return(metaRequest = CineastUtils.BuildMetadataRequest(CineastUtils.Configuration.FindMetadataUrl(), CineastUtils.ExtractIdArray(segmentResult.content))); earlyBreak = !Parse(metaRequest.text, out metaResult); yield return(metaResult); if (earlyBreak) { yield break; } // meta->mmo objectList = CineastUtils.Convert(metaResult.content); // === OBJECTS === yield return(objectRequest = CineastUtils.BuildObjectsRequest(CineastUtils.Configuration.FindObjectsUrl(), CineastUtils.ExtractIdArray(objectList.ToArray()))); yield return(objectsResult = JsonUtility.FromJson <ObjectsResult>(objectRequest.text)); // merge results List <MultimediaObject> objects = CineastUtils.Convert(objectsResult.content); foreach (MultimediaObject mmo in objects) { if (objectList.Contains(mmo)) { objectList.Find(o => o.Equals(mmo)).Merge(mmo); } } results = new List <MultimediaObject>(objectList); // === WRAPUP === foreach (MultimediaObject mmo in objectList) { mmo.resultIndex = CineastUtils.GetIndexOf(mmo, similarResult) + 1; } // === SORT LIST === objectList.Sort(Comparison); List <MultimediaObject> transferList; if (filterEngine != null) { // logger.Debug("FilterEngine installed with " + filterEngine.GetFilterCount() + " filters."); transferList = filterEngine.ApplyFilters(objectList); } else { // logger.Debug("No FilterEngine installed - no filtering"); transferList = objectList; } // cleanup finished = true; if (guid == null) { // LEGACY if (queryFinishedCallback != null) { // logger.Info("Query completed, passing resulting MultimediaObject list to callback"); queryFinishedCallback.Invoke(transferList); } } else { CineastResponseHandler <List <MultimediaObject> > handler = _guidHandlerMap[guid]; if (handler != null) { handler.onSuccess(transferList); } } yield return(true); }