예제 #1
0
        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);
        }
예제 #2
0
        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);
        }