<commit_before>﻿/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author <NAME> (<EMAIL>)
*/

#define TEST_WOODSIDE

using System.Collections;
using IBM.Watson.Services.v1;
using IBM.Watson.Logging;
using IBM.Watson.Data.XRAY;

namespace IBM.Watson.UnitTests
{
    public class TestXRAY : UnitTest
    {
#if TEST_WOODSIDE
        const string TEST_QUESTION = "When were Angel high rate trials conducted?";
        const string TEST_PIPELINE = "woodside";
#else
        const string TEST_QUESTION = "What is the capital of Texas";
        const string TEST_PIPELINE = "thunderstone";
#endif

        XRAY m_XRAY = new XRAY();
        bool m_AskQuestionTested = false;
        bool m_GetQuestionTested = false;
        bool m_GetAnswersTested = false;
        bool m_ParseTested = false;

        public override IEnumerator RunTest()
        {
            m_XRAY.DisableCache = true;
            m_XRAY.AskQuestion( TEST_PIPELINE, TEST_QUESTION, OnAskQuestion );
            while(! m_AskQuestionTested )
                yield return null;

            while (!m_GetQuestionTested)
                yield return null;
            while (!m_GetAnswersTested)
                yield return null;
            while (!m_ParseTested)
                yield return null;

            yield break;<commit_msg>* Enabled woodside question cache for woodside.<commit_after>﻿/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author <NAME> (<EMAIL>)
*/

#define TEST_WOODSIDE
#define CACHE_QUESTIONS
//#define EXPORT_QUESTIONS

using System.Collections;
using IBM.Watson.Services.v1;
using IBM.Watson.Logging;
using IBM.Watson.Data.XRAY;

#if EXPORT_QUESTIONS || CACHE_QUESTIONS
using UnityEngine;
using System.Xml;
using System.Text;
using System.IO;
#endif

namespace IBM.Watson.UnitTests
{
    public class TestXRAY : UnitTest
    {
#if TEST_WOODSIDE
        const string TEST_QUESTION = "When were Angel high rate trials conducted?";
        const string TEST_PIPELINE = "woodside";
#else
        const string TEST_QUESTION = "What is the capital of Texas";
        const string TEST_PIPELINE = "thunderstone";
#endif

        XRAY m_XRAY = new XRAY();
        bool m_AskQuestionTested = false;
        bool m_GetQuestionTested = false;
        bool m_GetAnswersTested = false;
        bool m_ParseTested = false;

        public override IEnumerator RunTest()
        {
            m_XRAY.DisableCache = true;
            m_XRAY.AskQuestion( TEST_PIPELINE, TEST_QUESTION, OnAskQuestion );
            while(! m_AskQuestionTested )
                yield return null;

            while (!m_GetQuestionTested)
                yield return null;
            while (!m_GetAnswersTested)
                yield return null;
            while (!m_ParseTested)
                yield return null;

#if EXPORT_QUESTIONS || CACHE_QUESTIONS
            byte [] question_data = File.ReadAllBytes( Application.dataPath + "/../Docs/WoodsideQuestions.xml" );
            var xml = new XmlDocument();
            xml.LoadXml( Encoding.UTF8.GetString( question_data ) );

#if CACHE_QUESTIONS
            m_XRAY.DisableCache = false;
#endif

#if EXPORT_QUESTIONS
            StringBuilder WoodsideCSV = new StringBuilder();
#endif

            XmlElement answerKey = xml["answerkey"] as XmlElement;
            foreach( var node in answerKey.ChildNodes )
            {
                XmlElement question = node as XmlElement;
                if (question == null )
                    continue;

                string text = question.GetAttribute("text" );
                Log.Status( "TestDeepQA", "Question: {0}", text );

#if CACHE_QUESTIONS
                Test( m_XRAY.AskQuestion( TEST_PIPELINE, text, OnAskQuestion ) );
#endif

#if EXPORT_QUESTIONS
                if ( text.Contains( "," ) )
                    text = "\"" + text + "\"";
                WoodsideCSV.Append( text + ",question-woodside\r\n" );
#endif
            }

#if EXPORT_QUESTIONS
            File.WriteAllText( Application.dataPath + "/../Docs/WoodsideQuestions.csv", WoodsideCSV.ToString() );
#endif
#endif
            yield break;
{'fraction_non_alphanumeric': 0.08395917581359523, 'fraction_numerical': 0.0038513383400731755, 'mean_word_length': 2.5648592999313657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4535226', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1444, 'n_words': 469}