private IEnumerator ExecuteMultiQuery(SimilarQuery query, CategoryRatio ratio) { // === 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) { foreach (ResultObject ro in similarResult.results) { ContentObject.ArrayToStrig(ro.content); } ResultMerger merger = new ResultMerger(); tempResult = merger.Merge(similarResult.results, ratio) .ToArray(); ContentObject.ArrayToStrig(tempResult); } // === 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) { transferList = filterEngine.ApplyFilters(objectList); } else { transferList = objectList; } // cleanup finished = true; if (queryFinishedCallback != null) { queryFinishedCallback.Invoke(transferList); } yield return(true); }
/* * Query For Masteroiece ( Draw picture) */ private IEnumerator ExecuteQueryMoreLikeMasterpiece(SimilarQuery query) { // Since api is used several times it has to be set false on call finished = false; // === 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 } // === SEGMENTS === // segments yield return(segmentRequest = CineastUtils.BuildSegmentRequest(CineastUtils.Configuration.FindSegmentsByIdUrl(), CineastUtils.ExtractIdArray(CineastUtils.ExtractContentObjects(similarResult)))); // parse response earlyBreak = !Parse(segmentRequest.text, out segmentResult); yield return(segmentResult); if (earlyBreak) { yield break; } yield return(objectRequest = CineastUtils.BuildObjectsRequest(CineastUtils.Configuration.FindObjectsUrl(), CineastUtils.ExtractIdArray(segmentResult.content))); yield return(objectsResult = JsonUtility.FromJson <ObjectsResult>(objectRequest.text)); objectList = CineastUtils.Convert(objectsResult.content); // merge results var objects = CineastUtils.Convert(objectsResult.content); foreach (var mmo in objects) { if (objectList.Contains(mmo)) { objectList.Find(o => o.Equals(mmo)).Merge(mmo); } } results = new List <MultimediaObject>(objectList); // === WRAPUP === foreach (var mmo in objectList) { mmo.resultIndex = CineastUtils.GetIndexOf(mmo, similarResult) + 1; } // === SORT LIST === objectList.Sort( Comparison); List <MultimediaObject> transferList; if (filterEngine != null) { transferList = filterEngine.ApplyFilters(objectList); } else { transferList = objectList; } // cleanup finished = true; if (queryFinishedCallback != null) { queryFinishedCallback.Invoke(transferList); } yield return(true); }
// new for more like this private IEnumerator ExecuteQueryMoreLikeThis(MoreLikeThisQuery query) { // === SIMILAR === // Initial SimilarQuery yield return(similarRequest = CineastUtils.BuildMoreLikeThisRequest(CineastUtils.Configuration.FindSimilarSegmentsUrl(), query)); // Parse response earlyBreak = !Parse(similarRequest.text, out similarResult); yield return(similarResult); if (earlyBreak) { yield break; } //Debug.Log(similarResult.results[0].content[0].key); //Debug.Log(similarResult.results[0].content[0].value); //Debug.Log(similarResult.results[0].content[1].value); //Debug.Log(similarResult.results[0].content[2].value); // Check if empty if (similarResult.IsEmpty()) { earlyBreak = true; yield break; // Stop and } // === SEGMENTS === // segments yield return(segmentRequest = CineastUtils.BuildSegmentRequest(CineastUtils.Configuration.FindSegmentsByIdUrl(), CineastUtils.ExtractIdArray(CineastUtils.ExtractContentObjects(similarResult)))); // parse response earlyBreak = !Parse(segmentRequest.text, out segmentResult); yield return(segmentResult); if (earlyBreak) { yield break; } Debug.Log("SegmentsRes:" + segmentResult.content[0].objectId); // === 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; * }*/ //Debug.Log(metaResult.content.Length); // Debug.Log("MetaRes:" + metaResult.content[0].objectId); // meta->mmo //objectList = CineastUtils.Convert(metaResult.content); /* * object list List<MultimediaObject> * einzigs anderi List<multimediaobject> wär result * * was gits sunscht was isch de unterschied? * * CineasObject kame zu MMO s macher mit utils.Convertto... gits das? * * Mit probiere Objectresult.conten == cineastobject zu objectlist mache... nid für hanzi arrays gmacht * */ //tryin objeclist without meta //objectList = segmentResult.content; // === OBJECTS === /* * yield return objectRequest = * CineastUtils.BuildObjectsRequest(CineastUtils.Configuration.FindObjectsUrl(), * CineastUtils.ExtractIdArray(objectList.ToArray())); * * yield return objectsResult = JsonUtility.FromJson<ObjectsResult>(objectRequest.text); */ yield return(objectRequest = CineastUtils.BuildObjectsRequest(CineastUtils.Configuration.FindObjectsUrl(), CineastUtils.ExtractIdArray(segmentResult.content))); yield return(objectsResult = JsonUtility.FromJson <ObjectsResult>(objectRequest.text)); Debug.Log("ObjectRes:" + objectsResult.content[0].path); // new trsy objectList = CineastUtils.Convert(objectsResult.content); Debug.Log("New Test 474" + objectList[0].id); // 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); } } Debug.Log("Object id 487" + objectList[0].id); 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) { transferList = filterEngine.ApplyFilters(objectList); } else { transferList = objectList; } Debug.Log("Object id 513" + objectList[0].id); Debug.Log("Object id 514" + transferList[0].id); // cleanup finished = true; if (queryFinishedCallback != null) { queryFinishedCallback.Invoke(transferList); } yield return(true); }
private IEnumerator ExecuteMultiQuery(SimilarQuery query, CategoryRatio ratio) { // === SIMILAR === // Initial SimilarQuery logger.Debug("Starting initial similar request.\n" + JsonUtility.ToJson(query)); yield return(similarRequest = CineastUtils.BuildSimilarRequest(CineastUtils.Configuration.FindSimilarSegmentsUrl(), query)); logger.Debug("Received similar response: " + similarRequest.text); // Parse response earlyBreak = !Parse(similarRequest.text, out similarResult); yield return(similarResult); if (earlyBreak) { logger.Error("HTTP error upon similar response"); yield break; } logger.Info("Successfully parsed similar response"); // Check if empty if (similarResult.IsEmpty()) { earlyBreak = true; logger.Error("Empty similar result"); yield break; // Stop and } ContentObject[] tempResult = CineastUtils.ExtractContentObjects(similarResult); if (ratio != null && similarResult.results.Length > 1) { logger.Debug("Merging..."); foreach (ResultObject ro in similarResult.results) { logger.Debug("Result for category {0} contains {1} entries.\n\t{2}", ro.category, ro.content.Length, ContentObject.ArrayToStrig(ro.content)); } ResultMerger merger = new ResultMerger(); tempResult = merger.Merge(similarResult.results, ratio) .ToArray(); logger.Debug("After merge: {0} unique entries\n\t{1}", tempResult.Length, ContentObject.ArrayToStrig(tempResult)); } // === SEGMENTS === // segments logger.Debug("Starting segments query"); yield return(segmentRequest = CineastUtils.BuildSegmentRequest(CineastUtils.Configuration.FindSegmentsByIdUrl(), CineastUtils.ExtractIdArray(tempResult))); logger.Debug("Received segments response:\n" + segmentRequest.text); // parse response earlyBreak = !Parse(segmentRequest.text, out segmentResult); yield return(segmentResult); if (earlyBreak) { logger.Error("HTTP error upon segments response"); yield break; } logger.Info("Successfully parsed segments response"); // === METAS === logger.Debug("Starting metadata request"); yield return(metaRequest = CineastUtils.BuildMetadataRequest(CineastUtils.Configuration.FindMetadataUrl(), CineastUtils.ExtractIdArray(segmentResult.content))); logger.Debug("Received metadata response:\n" + metaRequest.text); earlyBreak = !Parse(metaRequest.text, out metaResult); yield return(metaResult); if (earlyBreak) { logger.Error("HTTP error upon metadata response"); yield break; } logger.Info("Successfully parsed metadata response"); // meta->mmo objectList = CineastUtils.Convert(metaResult.content); logger.Info("Successfully converted metadata result to MultimediaObjects"); // === OBJECTS === logger.Debug("Starting object query"); yield return(objectRequest = CineastUtils.BuildObjectsRequest(CineastUtils.Configuration.FindObjectsUrl(), CineastUtils.ExtractIdArray(objectList.ToArray()))); logger.Debug("Received objects response:\n" + objectRequest.text); yield return(objectsResult = JsonUtility.FromJson <ObjectsResult>(objectRequest.text)); logger.Info("Successfully parsed objects response"); // merge results List <MultimediaObject> objects = CineastUtils.Convert(objectsResult.content); logger.Debug("Successfully converted object result to MultimediaObjects"); foreach (MultimediaObject mmo in objects) { if (objectList.Contains(mmo)) { objectList.Find(o => o.Equals(mmo)).Merge(mmo); } } logger.Info("Finished merging different MultimediaObject lists"); results = new List <MultimediaObject>(objectList); // === WRAPUP === logger.Debug("Applying result index to MultimediaObject list"); foreach (MultimediaObject mmo in objectList) { mmo.resultIndex = CineastUtils.GetIndexOf(mmo, similarResult) + 1; } logger.Info("Result contains " + objectList.Count + " entities"); logger.Debug("Full result list:\n" + DumpMMOList(objectList)); // === SORT LIST === logger.Debug("Sorting list"); objectList.Sort( Comparison); logger.Debug("Sorted list: \n" + DumpMMOList(objectList)); 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 (queryFinishedCallback != null) { logger.Info("Query completed, passing resulting MultimediaObject list to callback"); queryFinishedCallback.Invoke(transferList); } yield return(true); }