Exemple #1
0
        public async Task <ActionResult <TermList> > GetTermsByStringMatch(string str)
        {
            _logger.LogInformation($"[api/cipo] {DateTime.Now} - Searched for term {str} .");
            var termsByString = await _context.NICETerms.Where(t => t.Name.Contains(str)).ToArrayAsync();

            _logger.LogInformation($"[api/cipo] {DateTime.Now} - Search returned {termsByString.Length} terms.");

            var termlist = new TermList()
            {
                Terms = new Term[termsByString.Length]
            };


            for (int i = 0; i < termsByString.Length; i++)
            {
                Term t = new Term()
                {
                    Id       = termsByString[i].Id,
                    TermName = termsByString[i].Name
                };

                termlist.Terms[i] = t;
            }

            return(termlist);
        }
Exemple #2
0
        public string GetRandomTerm(TermList termList)
        {
            Random r            = new Random();
            int    index        = 0;
            string randomString = "";

            switch (termList)
            {
            case TermList.Tamed:
                index        = r.Next(_savedVerbs.Count);
                randomString = _savedVerbs[index];
                break;

            case TermList.Crash:
                index        = r.Next(_crashVerbs.Count);
                randomString = _crashVerbs[index];
                break;

            case TermList.Safe:
                index        = r.Next(_safeAdjectives.Count);
                randomString = _safeAdjectives[index];
                break;

            case TermList.Unsafe:
                index        = r.Next(_unsafeAdjectives.Count);
                randomString = _unsafeAdjectives[index];
                break;
            }

            return(randomString);
        }
 public BasicArgument()
 {
     ArtistID = new TermList();
     Artist   = new TermList();
     SongID   = new TermList();
     TrackID  = new TermList();
 }
Exemple #4
0
 private void SetTermList(int number)
 {
     for (var i = 1; i <= number; i++)
     {
         TermList.Add(item: i.ToString());
     }
 }
Exemple #5
0
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            //arrange
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca = true
            };

            TermList artistTerms = new TermList { artistName };
            basicArgument.Artist.AddRange(artistTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
               //act
                PlaylistResponse searchResponse = session.Query<Basic>().Execute(basicArgument);

                //assert
                Assert.IsNotNull(searchResponse);

                // output
                Console.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
Exemple #6
0
        private void TabSubjectOnReturn(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }

            var subject = ((FrameworkElement)sender).DataContext as SubjectViewModel;

            if (subject == null)
            {
                return;
            }

            e.Handled = true;
            int row = set.Subjects.IndexOf(subject);

            if (row == set.Subjects.Count - 1)
            {
                AddNew(sender, e);
            }
            else
            {
                TermList.ScrollIntoView(set.Subjects[row]);
                Debug.Assert(SubjectList.ItemContainerGenerator != null, "SubjectList.ItemContainerGenerator != null");
                FocusTextBox(SubjectList.ItemContainerGenerator.ContainerFromIndex(row + 1) as FrameworkElement);
            }
        }
Exemple #7
0
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            //arrange
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca    = true
            };

            TermList artistTerms = new TermList {
                artistName
            };

            basicArgument.Artist.AddRange(artistTerms);


            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                //act
                PlaylistResponse searchResponse = session.Query <Basic>().Execute(basicArgument);

                //assert
                Assert.IsNotNull(searchResponse);

                // output
                Console.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
 public BasicArgument()
 {
     ArtistID = new TermList();
     Artist = new TermList();
     SongID = new TermList();
     TrackID = new TermList();
 }
Exemple #9
0
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca = true
            };

            TermList artistTerms = new TermList { artistName };
            basicArgument.Artist.AddRange(artistTerms);

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query<Basic>().Execute(basicArgument);

                Assert.IsNotNull(searchResponse);

                System.Diagnostics.Debug.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }

            }
        }
Exemple #10
0
        public static IExtTerm BinaryToTerm(EndianBinaryReader reader, bool needMarker = true)
        {
            if (needMarker)
            {
                var marker = reader.ReadByte();
                if (marker != TermStartMarker)
                {
                    throw new BadTermMarkerException(marker, TermStartMarker);
                }
            }

            var      tag   = (EExtTermType)reader.ReadByte();
            IExtTerm value = tag switch
            {
                EExtTermType.List => TermList.Read(reader),
                EExtTermType.Tuple8 => TermTuple.Read(reader, ETermSize.Small),
                EExtTermType.Tuple32 => TermTuple.Read(reader, ETermSize.Large),
                EExtTermType.AtomLatin18 => TermAtom.Read(reader, EEncodingType.Latin1, ETermSize.Small),
                EExtTermType.AtomLatin116 => TermAtom.Read(reader, EEncodingType.Latin1, ETermSize.Large),
                EExtTermType.AtomUtf88 => TermAtom.Read(reader, EEncodingType.Utf8, ETermSize.Small),
                EExtTermType.AtomUtf816 => TermAtom.Read(reader, EEncodingType.Utf8, ETermSize.Large),
                EExtTermType.String => TermString.Read(reader),
                EExtTermType.Nil => TermNil.Read(),
                EExtTermType.FloatString => TermFloatString.Read(reader),
                EExtTermType.Int32 => TermInt32.Read(reader),
                EExtTermType.UInt8 => TermUInt8.Read(reader),
                EExtTermType.Big8 => TermBigNumber.Read(reader, ETermSize.Small),
                EExtTermType.Big32 => TermBigNumber.Read(reader, ETermSize.Large),
                EExtTermType.NewFloat64 => TermNewFloat64.Read(reader),
                EExtTermType.Binary => TermBinary.Read(reader),
                _ => throw new NotImplementedException($"{tag} not supported"),
            };

            return(value);
        }
Exemple #11
0
 private void FillTermList(Term[] terms, TermList target)
 {
     foreach (var term in terms)
     {
         target.Add(term);
     }
 }
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca    = true
            };

            TermList artistTerms = new TermList {
                artistName
            };

            basicArgument.Artist.AddRange(artistTerms);

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query <Basic>().Execute(basicArgument);

                Assert.IsNotNull(searchResponse);

                System.Diagnostics.Debug.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
            }
        }
        public void GetFourtyRunningSongs(string query)
        {
            var id      = GetSongId(query);
            var songIds = new TermList();

            songIds.Add(id);

            StaticArgument staticArgument = new StaticArgument
            {
                Type     = "song-radio",
                SongID   = songIds,
                Results  = 40,
                MinTempo = 88,
                MaxTempo = 92,
                Variety  = 1
            };


            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Assert.AreEqual(40, searchResponse.Songs.Count);
            }
        }
 public static WikitextDocument Parse(string wikitext)
 {
     return(new WikitextDocument()
     {
         Elements = TermList.Parse(wikitext)
     });
 }
        public static Term FunCall(string fname, IList <Term> typeArgs, IList <Term> args)
        {
            var wrapTypeArgs = new TermList(typeArgs);
            var wrapArgs     = new TermList(args);
            var fnameAndArgs = new List <Term> {
                new StringConst(fname), wrapTypeArgs, wrapArgs
            };

            return(new TermApp(funCallId, fnameAndArgs));
        }
 public GenericFunction(string name, IEnumerable<Term> arguments)
 {
     Name = name;
     var list = new TermList();
     foreach (var term in arguments)
     {
         list.AddTerm(term);
     }
     Arguments = list;
 }
        public static Term Program(Term fdecls, Term constantDecls, Term globalDecls, Term axioms, List <Term> mdecls)
        {
            Term mdeclsTerm = new TermList(mdecls);

            return(new TermApp(IsaCommonTerms.TermIdentFromName("Program"),
                               new List <Term>
            {
                new TermList(new List <Term>()), fdecls, constantDecls, globalDecls, axioms, mdeclsTerm
            }));
        }
Exemple #18
0
        public void GetSongs_ForApocalypseNow_ExpectedArtist(string title, string styles, string moods, string expect)
        {
            // arrange
            TermList styleTerms = new TermList();

            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();

            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            SearchArgument searchArgument = new SearchArgument
            {
                Mode    = "0", /* minor */
                Sort    = "artist_familiarity-desc",
                Results = 10
            };

            searchArgument.Styles.AddRange(styleTerms);

            searchArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                SearchResponse searchResponse = session.Query <Search>().Execute(searchArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);

                var matches = (from s in searchResponse.Songs
                               where s.ArtistName.ToLower().Contains(expect)
                               select s).ToList();


                Assert.IsNotNull(matches, "Failed to find songs where artist name contains: {0}", expect);

                // output
                Console.WriteLine("Tracks for '{0}'", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }
Exemple #19
0
    public void Sets_Properties()
    {
        // Arrange
        var taxonomy = Taxonomy.Blank;

        // Act
        var result = new TermList(taxonomy);

        // Assert
        Assert.Same(taxonomy, result.Taxonomy);
    }
 internal AzureTermList(TermList azureTermList, IAzureTermListApi api, string language = "eng")
 {
     OriginalTermList = azureTermList;
     if (OriginalTermList != null)
     {
         ListID = OriginalTermList.Id.Value;
         Name   = OriginalTermList.Name;
     }
     Language  = language;
     API       = api;
     IsDeleted = false;
 }
    protected void btnAddRow_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        lbError.Visible = false;
        if (txtValue.Value.Length > 0)
        {
            if (ifcObj.Type == InputFormContainerType.MultiChoiceList && txtValue.Value.ToString().IndexOf(';') >= 0)
            {
                lbError.CssClass = "hc_error";
                lbError.Text     = "Value cannot contain the ';' character";
                lbError.Visible  = true;
            }
            else
            {
                //#ACQ8.20 Starts
                //InputFormValue IFValue = new InputFormValue(-1, InputFormContainerId, -1, dgValues.Rows.Count + 1, txtValue.Value, txtComment.Text, SessionState.User.Id, -1, DateTime.UtcNow, null);
                //QC2691 Check for validation of Terms if it already exists was not there so added
                TermList       Termdetails = Term.GetAll("TermValue = '" + txtValue.Value + "' AND TermTypeCode='C'");
                InputFormValue IFValue;
                if (Termdetails == null || Termdetails.Count == 0) //#2712
                //if (Termdetails == null) //#2712 Commented
                {
                    IFValue = new InputFormValue(-1, InputFormContainerId, -1, dgValues.Rows.Count + 1, txtValue.Value, txtComment.Text, IsTranslateDefaultOption, SessionState.User.Id, -1, DateTime.UtcNow, null);
                }
                else
                {
                    IFValue = new InputFormValue(-1, InputFormContainerId, -1, dgValues.Rows.Count + 1, txtValue.Value, txtComment.Text, Termdetails[0].IsTranslatable, SessionState.User.Id, -1, DateTime.UtcNow, null);
                }

                //#ACQ8.20 Ends


                if (!IFValue.Save())
                {
                    lbError.CssClass = "hc_error";
                    lbError.Text     = InputFormValue.LastError;
                    lbError.Visible  = true;
                }
                else
                {
                    txtComment.Text = string.Empty;
                    txtValue.Value  = string.Empty;
                    UpdateDataEdit();
                }
            }
        }
        else
        {
            lbError.CssClass = "hc_error";
            lbError.Text     = "Value cannot be empty";
            lbError.Visible  = true;
        }
    }
 public static bool VerifyTermListContents(Body expected, TermList actual)
 {
     try
     {
         return(expected.Name.Equals(actual.Name, StringComparison.InvariantCultureIgnoreCase) &&
                expected.Metadata["Key One"].Equals(actual.Metadata["Key One"], StringComparison.InvariantCultureIgnoreCase) &&
                expected.Metadata["Key Two"].Equals(actual.Metadata["Key Two"], StringComparison.InvariantCultureIgnoreCase));
     }
     catch (Exception e)
     {
         throw new Exception("Unable to verify Term list correctness. Error:" + e.InnerException.Message);
     }
 }
Exemple #23
0
        public void GetSongs_ForApocalypseNow_ExpectedArtist(string title, string styles, string moods, string expect)
        {
            // arrange
            TermList styleTerms = new TermList();
            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();
            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            SearchArgument searchArgument = new SearchArgument
            {
                Mode = "0", /* minor */
                Sort = "artist_familiarity-desc",
                Results = 10
            };

            searchArgument.Styles.AddRange(styleTerms);

            searchArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                SearchResponse searchResponse = session.Query<Search>().Execute(searchArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);

                var matches = (from s in searchResponse.Songs
                               where s.ArtistName.ToLower().Contains(expect)
                               select s).ToList();

                Assert.IsNotNull(matches, "Failed to find songs where artist name contains: {0}", expect);

                // output
                Console.WriteLine("Tracks for '{0}'", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }
Exemple #24
0
        private async Task <string> CreateTermListAsync(string name, string description, CancellationToken cancellationToken = default)
        {
            try
            {
                var      body = new Body(name, description);
                TermList list = await _contentModeratorClient.ListManagementTermLists.CreateAsync("application/json", body, cancellationToken);

                return(list.Id.Value.ToString());
            }
            catch (APIErrorException e)
            {
                throw new HttpStatusErrorException(e.Response.StatusCode, e.Response.Content);
            }
        }
Exemple #25
0
        public IActionResult RequestAbonement()
        {
            var currentClient = context.Client.Single(x => x.Email == User.Identity.Name);

            ViewData["MyRequests"] = context.RequestAbonement.Where(x => x.IdClient == currentClient.Id).ToList();
            ViewData["TermList"]   = TermList.Select(x => new SelectListItem {
                Text = x.ToString(), Value = x.ToString()
            });
            ViewData["TimeList"] = TimeList.Select(x => new SelectListItem {
                Text = x.ToString(@"hh\:mm"), Value = x.ToString()
            });

            return(View(Roles.Client));
        }
Exemple #26
0
        public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods)
        {
            //arrange
            TermList styleTerms = new TermList();

            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();

            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            StaticArgument staticArgument = new StaticArgument
            {
                Results         = 25,
                Adventurousness = 0.4,
                Type            = "artist-description",
                Variety         = 0.4 /* variety of artists */
            };

            staticArgument.Styles.AddRange(styleTerms);

            staticArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                //act
                PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                // output
                Console.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
Exemple #27
0
        private static void Basic(EchoNestSession session)
        {
            String query = String.Empty;

            ConsoleEx.WriteLine("=== Basic Playlist Generation ===", ConsoleColor.Cyan);
            ConsoleEx.WriteLine("(Enter a comma separated list of artist names for generating a baisc 'artist-radio' type playlist)", ConsoleColor.Cyan);

            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            query = Console.ReadLine();

            if (String.IsNullOrEmpty(query))
            {
                ConsoleEx.WriteLine("Query was empty. Press any key to start over.", ConsoleColor.Cyan);
                Console.ReadLine();
                Basic(session);
            }

            ConsoleEx.WriteLine("Generating..", ConsoleColor.Yellow);

            BasicArgument basicArgument = new BasicArgument();

            string[] terms = query.Split(',');

            TermList artistTerms = new TermList();

            foreach (string term in terms)
            {
                artistTerms.Add(term.Trim());
            }

            basicArgument.Artist.AddRange(artistTerms);

            var result = session.Query <Basic>().Execute(basicArgument);

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Exemple #28
0
        public static List <TermList> GetTermLists(int subjectId)
        {
            var db     = new ApplicationDbContext();
            var dbList = new List <TermList>();

            foreach (var term in db.Terms)
            {
                var termList = new TermList();
                termList.TermID          = term.TermID;
                termList.Name            = term.Name;
                termList.AssessmentLists = GetAssessmentLists(subjectId, term.TermID);
                dbList.Add(termList);
            }
            return(dbList);
        }
Exemple #29
0
        private static void Basic(EchoNestSession session)
        {
            String query = String.Empty;

            ConsoleEx.WriteLine("=== Basic Playlist Generation ===", ConsoleColor.Cyan);
            ConsoleEx.WriteLine("(Enter a comma separated list of artist names for generating a baisc 'artist-radio' type playlist)", ConsoleColor.Cyan);

            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            query = Console.ReadLine();

            if (String.IsNullOrEmpty(query))
            {
                ConsoleEx.WriteLine("Query was empty. Press any key to start over.", ConsoleColor.Cyan);
                Console.ReadLine();
                Basic(session);
            }

            ConsoleEx.WriteLine("Generating..", ConsoleColor.Yellow);

            BasicArgument basicArgument = new BasicArgument();

            string[] terms = query.Split(',');

            TermList artistTerms = new TermList();
            foreach (string term in terms)
            {
                artistTerms.Add(term.Trim());
            }

            basicArgument.Artist.AddRange(artistTerms);

            var result = session.Query<Basic>().Execute(basicArgument);

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
        private PlaylistResponse GetSongPlaylist(EchoNestSession session, string query)
        {
            var id = GetSongId(session, query);
            var songIds = new TermList();
            songIds.Add(id);

            StaticArgument staticArgument = new StaticArgument
            {
                Type = "song-radio",
                SongID = songIds,
                Results = 40,
                Variety = 1
            };

            return session.Query<Static>().Execute(staticArgument);
        }
Exemple #31
0
        /// <summary>Get the current List of HC_ and load if necessary.</summary>
        private static CollectionView GetTerms()
        {
            Cache          c    = HttpRuntime.Cache;
            CollectionView view = (CollectionView)c[CACHEENTRYNAME];

            if (view == null)
            {
                using (TermList Terms = HyperCatalog.Business.Term.GetAll("TermTypeCode = 'C'"))
                {
                    view = new CollectionView(Terms);
                    view.ApplySort("Value", System.ComponentModel.ListSortDirection.Ascending);
                    c.Insert(CACHEENTRYNAME, view, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(30), CacheItemPriority.High, null);
                }
            } // if
            return(view);
        }     // Load
Exemple #32
0
        private void FinalizeProperty()
        {
            if (_property != null)
            {
                if (_terms.Length > 1)
                {
                    _property.Term = _terms;
                }
                else
                {
                    _property.Term = _terms[0];
                }
            }

            _terms    = new TermList();
            _property = null;
        }
Exemple #33
0
        ////// Métodos de gestión de listas
        static async Task <string> CrearListaTerminos(ContentModeratorClient client)
        {
            //Creamos la lista
            TermList lista = await client.ListManagementTermLists.CreateAsync("application/json", new Body("palabras_prohibidas"));

            string listaId = lista.Id.ToString();

            //Añadimos los términos
            await client.ListManagementTerm.AddTermAsync(listaId, "Facebook", "spa");

            await client.ListManagementTerm.AddTermAsync(listaId, "Instagram", "spa");

            //Refrescamos el índice de la lista
            await client.ListManagementTermLists.RefreshIndexMethodAsync(listaId, "spa");

            return(listaId);
        }
        public MortgageViewModel()
        {
            StartDate     = DateTime.Now;
            PurchasePrice = 100000;
            IntSlider     = 4;
            YrsSlider     = 30;

            termList = new ObservableCollection <LoanPeriod>();
            LoanPeriod temp  = new LoanPeriod(1, 5);
            LoanPeriod temp1 = new LoanPeriod(2, 10);
            LoanPeriod temp2 = new LoanPeriod(3, 15);
            LoanPeriod temp3 = new LoanPeriod(4, 30);

            TermList.Add(temp);
            TermList.Add(temp1);
            TermList.Add(temp2);
            TermList.Add(temp3);
        }
        public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods)
        {
            TermList styleTerms = new TermList();

            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();

            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            StaticArgument staticArgument = new StaticArgument
            {
                Results         = 25,
                Adventurousness = 0.4,
                Type            = "artist-description",
                Variety         = 0.4 /* variety of artists */
            };

            staticArgument.Styles.AddRange(styleTerms);

            staticArgument.Moods.AddRange(moodTerms);

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                System.Diagnostics.Debug.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
            }
        }
        public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods)
        {
            TermList styleTerms = new TermList();
            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();
            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 25,
                Adventurousness = 0.4,
                Type = "artist-description",
                Variety = 0.4 /* variety of artists */
            };

            staticArgument.Styles.AddRange(styleTerms);

            staticArgument.Moods.AddRange(moodTerms);

            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Console.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }

                Console.WriteLine();
            }
        }
Exemple #37
0
        /// <summary>
        /// Creates a new term list.
        /// </summary>
        /// <param name="client">The Content Moderator client.</param>
        /// <returns>The term list ID.</returns>
        static string CreateTermList(ContentModeratorClient client)
        {
            Console.WriteLine("Creating term list.");

            Body     body = new Body("Term list name", "Term list description");
            TermList list = client.ListManagementTermLists.Create("application/json", body);

            if (false == list.Id.HasValue)
            {
                throw new Exception("TermList.Id value missing.");
            }
            else
            {
                string list_id = list.Id.Value.ToString();
                Console.WriteLine("Term list created. ID: {0}.", list_id);
                Thread.Sleep(throttleRate);
                return(list_id);
            }
        }
Exemple #38
0
        private void StaticConfigProvider_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "IsTermUpper":
                if (StaticConfigProvider.IsTermUpper == true)
                {
                    TermList = TermList.Select(x => x.ToUpper()).ToList();
                }
                else
                {
                    TermList = TermList.Select(x => x.ToLower()).ToList();
                }
                break;

            case "IsTranslationUpper":
                if (StaticConfigProvider.IsTranslationUpper == true)
                {
                    TranslationList = TranslationList.Select(x => x.ToUpper()).ToList();
                }
                else
                {
                    TranslationList = TranslationList.Select(x => x.ToLower()).ToList();
                }
                break;

            case "IsTestOn":
                if (StaticConfigProvider.IsTestOn == true)
                {
                    WordsDictionary = ReadFromFileService.ReturnWordsDictionary();
                    IsTestOn        = true;
                }
                else
                {
                    IsTestOn = false;
                }
                break;

            case "IsTestOpenFirstly":
                IsTestOpenFirstly = StaticConfigProvider.IsTestOpenFirstly;
                break;
            }
        }
        private PlaylistData CreateEchonestPlaylist(string apiKey)
        {
            var seedArtists = new TermList();

            seedArtists.Add(Query);

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 40,
                Artist = seedArtists,
                Type = "artist-radio"
            };

            using (var session = new EchoNestSession(apiKey))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);
                var playlistData = new PlaylistData();
                playlistData.Items = new List<PlaylistDataItem>();
                playlistData.Description = Query;
                playlistData.Title = string.Format("{0} playlist", Query);
                playlistData.SearchKeys = new List<string>();

                foreach (var song in searchResponse.Songs)
                {
                    var item = new PlaylistDataItem();
                    item.Artist = song.ArtistName;
                    item.Title = song.Title;
                    playlistData.Items.Add(item);

                    var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                    playlistData.SearchKeys.Add(searchKey);
                }

                return playlistData;
            }
        }
    private bool ParseMediaValue(Block token)
    {
      switch (token.GrammarSegment)
      {
        case GrammarSegment.CurlyBraceOpen:
        case GrammarSegment.Semicolon:
          {
            var container = CurrentRule as ISupportsMedia;

            if (container != null)
            {
              container.Media.AppendMedium(_mediaDefn);
            }

            if (CurrentRule is ImportRule)
            {
              return ParsePostInstruction(token);
            }

            SetParsingContext(ParsingContext.DataBlock);
            _mediaDefn = null;
            return token.GrammarSegment == GrammarSegment.CurlyBraceOpen;
          }
        case GrammarSegment.Comma:
          {
            var container = CurrentRule as ISupportsMedia;

            if (container != null)
            {
              container.Media.AppendMedium(_mediaDefn);
            }
            _mediaDefn = null;
            return true;
          }
        case GrammarSegment.Whitespace:
          {
            // Do Nothing
            return true;
          }
        default:
          {
            if (_mediaDefn == null) _mediaDefn = new MediaDefinition();
            switch (token.ToString())
            {
              case "only":
                _mediaDefn.Modifier = MediaTypeModifier.Only;
                break;
              case "not":
                _mediaDefn.Modifier = MediaTypeModifier.Not;
                break;
              case "screen":
                _mediaDefn.Type = MediaType.Screen;
                break;
              case "speech":
                _mediaDefn.Type = MediaType.Speech;
                break;
              case "print":
                _mediaDefn.Type = MediaType.Print;
                break;
              case "all":
                _mediaDefn.Type = MediaType.All;
                break;
              case "braille":
                _mediaDefn.Type = MediaType.Braille;
                break;
              case "embossed":
                _mediaDefn.Type = MediaType.Embossed;
                break;
              case "handheld":
                _mediaDefn.Type = MediaType.Handheld;
                break;
              case "projection":
                _mediaDefn.Type = MediaType.Projection;
                break;
              case "tty":
                _mediaDefn.Type = MediaType.Tty;
                break;
              case "tv":
                _mediaDefn.Type = MediaType.Tv;
                break;
              case "and":
                // do nothing
                break;
              case "(":
                _mediaProp = new MediaProperty();
                break;
              case ")":
                if (_mediaProp != null)
                {
                  var plain = _mediaProp as MediaPropertyPlain;
                  if (plain != null && _terms.Length == 1)
                  {
                    plain.Value = _terms[0];
                  }
                  else if (!string.IsNullOrEmpty(_compare1) && _terms.Length > 0)
                  {
                    var range = new MediaPropertyRange { Name = _mediaProp.Name };
                    if (_nameFirst)
                    {
                      if (_compare1.StartsWith("<"))
                      {
                        range.UpperBound = _terms[0];
                        range.UpperCompare = _compare1;
                      }
                      else
                      {
                        range.LowerBound = _terms[0];
                        range.LowerCompare = _compare1.Replace('>', '<');
                      }
                    }
                    else
                    {
                      if (_terms.Length == 1)
                      {
                        if (_compare1.StartsWith(">"))
                        {
                          range.UpperBound = _terms[0];
                          range.UpperCompare = _compare1.Replace('>', '<');
                        }
                        else
                        {
                          range.LowerBound = _terms[0];
                          range.LowerCompare = _compare1;
                        }
                      }
                      else
                      {
                        if (_compare1.StartsWith("<"))
                        {
                          range.LowerBound = _terms[0];
                          range.LowerCompare = _compare1;
                          range.UpperBound = _terms[1];
                          range.UpperCompare = _compare2;
                        }
                        else
                        {
                          range.UpperBound = _terms[0];
                          range.UpperCompare = _compare1.Replace('>', '<');
                          range.LowerBound = _terms[1];
                          range.LowerCompare = _compare2.Replace('>', '<');
                        } 
                      }
                    }
                    _mediaProp = range;
                  }
                  _mediaDefn.Properties.Add(_mediaProp);
                }
                _compare1 = null;
                _compare2 = null;
                _mediaProp = null;
                _terms = new TermList();
                break;
              case ":":
                if (_mediaProp != null) _mediaProp = new MediaPropertyPlain { Name = _mediaProp.Name };
                break;
              case "<":
              case ">":
                if (string.IsNullOrEmpty(_compare1))
                  _compare1 = token.ToString();
                else
                  _compare2 = token.ToString();
                break;
              case "=":
                if (string.IsNullOrEmpty(_compare1) || (string.IsNullOrEmpty(_compare2) && _compare1 != "="))
                  _compare1 = (_compare1 ?? "") + token.ToString();
                else
                  _compare2 = (_compare2 ?? "") + token.ToString();
                break;
              default:
                if (token.GrammarSegment == GrammarSegment.Ident && string.IsNullOrEmpty(_mediaProp.Name))
                {
                  _mediaProp.Name = token.ToString();
                  _nameFirst = string.IsNullOrEmpty(_compare1);
                }
                else
                {
                  ParseSingleValue(token);
                }
                break;
            }
            return true;
          }
      }
    }
Exemple #41
0
        public void GetPlaylistByArtistOrSong(string query)
        {
            var seedArtists = new TermList();
            seedArtists.Add(query);

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 40,
                Artist = seedArtists,
                Type = "artist-radio"
            };

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Assert.AreEqual(40, searchResponse.Songs.Count);
            }
        }
Exemple #42
0
        public void GetFourtyRunningSongs(string query)
        {
            var id = GetSongId(query);
            var songIds = new TermList();
            songIds.Add(id);

            StaticArgument staticArgument = new StaticArgument
            {
                Type = "song-radio",
                SongID = songIds,
                Results = 40,
                MinTempo = 88,
                MaxTempo = 92,
                Variety = 1
            };
                

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Assert.AreEqual(40, searchResponse.Songs.Count);
            }
        }
Exemple #43
0
 public Term(string term, TermList parent)
 {
     _term = term;
     _parent = parent;
 }
Exemple #44
0
 public StaticArgument()
 {
     Styles = new TermList();
     Moods = new TermList();
     Description = new TermList();
 }
        private void FillTermList(IEnumerable<TermModel> source, TermList target)
        {
            source.ForEach(s =>
            {
                var term = target.Add(s.Name);

                if (s.Boost.HasValue)
                {
                    term.Boost(s.Boost.Value);
                }

                if (s.Require)
                {
                    term.Require();
                }

                if (s.Ban)
                {
                    term.Ban();
                }
            });
        }
        private PlaylistResponse GetArtistPlaylist(EchoNestSession session, string query)
        {
            
            var seedArtists = new TermList();

            foreach (var term in query.Split(','))
            {
                seedArtists.Add(term);
            }

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 40,
                Artist = seedArtists,
                Type = "artist-radio"
            };

            return session.Query<Static>().Execute(staticArgument);
        }
 public SearchArgument()
 {
     Styles = new TermList();
     Moods = new TermList();
     Description = new TermList();
 }
Exemple #48
0
        public void GetDynamicPlaylist_WhereMoodAndStyle_CanSteerDynamicPlaylistByMood(string title, string styles, string moods)
        {
            //arrange
            TermList styleTerms = new TermList();
            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();
            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            DynamicArgument dynamicArgument = new DynamicArgument
            {
                Adventurousness = 0.4,
                Type = "artist-description",
                Variety = 0.4 /* variety of artists */
            };

            dynamicArgument.Styles.AddRange(styleTerms);

            dynamicArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                //act
                DynamicPlaylistResponse searchResponse = session.Query<Dynamic>().Execute(dynamicArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                // arrange next part of test
                string sessionId = searchResponse.SessionId;

                // output
                Console.WriteLine("Dynamic Playlist Session Id: {0}", sessionId);
                Console.WriteLine();
                Console.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
                Console.WriteLine("Steering Playlist by mood = -happy");
                Console.WriteLine();

                dynamicArgument = new DynamicArgument { SteerMood = "-happy", SessionId = sessionId };
                searchResponse = session.Query<Dynamic>().Execute(dynamicArgument);
                Console.WriteLine("Next song in dynamic playlist for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }

                Console.WriteLine();
                Console.WriteLine("Steering Playlist by tempo = +10% (tempo^1.1)");
                Console.WriteLine();
                dynamicArgument = new DynamicArgument { Steer = "tempo^1.1", SessionId = sessionId };
                searchResponse = session.Query<Dynamic>().Execute(dynamicArgument);
                Console.WriteLine("Next song in dynamic playlist for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
Exemple #49
0
    public static IEnumerable<Property> Expand(this Property style, bool leftToRight)
    {
      Dictionary<string, Property> children;
      PrimitiveTerm prim;
      Term current;
      TermList list;
      IList<Term> terms;

      switch(style.Name.ToLowerInvariant())
      {
        case "background":
          children = new Dictionary<string, Property>()
          {
            {"background-color",    new Property("background-color")    { Term = new InitialTerm() }},
            {"background-image",    new Property("background-image")    { Term = new InitialTerm() }},
            {"background-repeat",   new Property("background-repeat")   { Term = new InitialTerm() }},
            {"background-position", new Property("background-position") { Term = new InitialTerm() }}
          };

          foreach (var term in GetEnumerable(style.Term))
          {
            if (term is HtmlColor)
            {
              children["background-color"].Term = term;
            }
            else
            {
              prim = term as PrimitiveTerm;
              if (prim != null)
              {
                if (prim.PrimitiveType == UnitType.Uri)
                {
                  children["background-image"].Term = term;
                }
                else if (prim.PrimitiveType == UnitType.Ident)
                {
                  switch (prim.Value.ToString())
                  {
                    case "repeat-x":
                    case "repeat-y":
                    case "repeat":
                    case "space":
                    case "round":
                    case "no-repeat":
                      current = children["background-repeat"].Term;
                      list = current as TermList;
                      if (list != null)
                      {
                        list.AddTerm(prim);
                      }
                      else if (current is InitialTerm)
                      {
                        children["background-repeat"].Term = prim;
                      }
                      else
                      {
                        list = new TermList();
                        list.AddTerm(current);
                        list.AddTerm(prim);
                        children["background-repeat"].Term = list;
                      }
                      break;
                  }
                }
              }
            }
          }

          foreach (var val in children.Values) yield return val;
          break;
        case "font":
          children = new Dictionary<string, Property>()
          {
            {"font-style",    new Property("font-style")    { Term = new InitialTerm() }},
            {"font-weight",   new Property("font-weight")   { Term = new InitialTerm() }},
            {"font-size",     new Property("font-size")     { Term = new InitialTerm() }},
            {"line-height",   new Property("line-height")   { Term = new InitialTerm() }},
            {"font-family",   new Property("font-family")   { Term = new InitialTerm() }}
          };

          foreach (var term in GetEnumerable(style.Term))
          {
            prim = term as PrimitiveTerm;
            if (prim != null)
            {
              if (prim.PrimitiveType == UnitType.Number)
              {
                switch (prim.Value.ToString())
                {
                  case "100":
                  case "200":
                  case "300":
                  case "400":
                  case "500":
                  case "600":
                  case "700":
                  case "800":
                  case "900":
                    children["font-weight"].Term = term;
                    break;
                  default:
                    children["line-height"].Term = term;
                    break;
                }
              }
              else if (prim.PrimitiveType == UnitType.Ident)
              {
                switch (prim.Value.ToString())
                {
                  case "italic":
                  case "oblique":
                    children["font-style"].Term = term;
                    break;
                  case "bold":
                  case "bolder":
                  case "lighter":
                    children["font-weight"].Term = term;
                    break;
                  default:
                    list = term as TermList;
                    if (list != null)
                    {
                      list.AddTerm(prim);
                    }
                    else if (term is InitialTerm)
                    {
                      children["font-family"].Term = prim;
                    }
                    else
                    {
                      list = new TermList();
                      list.AddTerm(term);
                      list.AddTerm(prim);
                      children["font-family"].Term = list;
                    }
                    break;
                }
              }
              else
              {
                children["font-size"].Term = term;
              }
            }
          }

          foreach (var val in children.Values) yield return val;
          break;
        case "border":
          children = new Dictionary<string, Property>()
          {
            {"border-width",    new Property("border-width")    { Term = new InitialTerm() }},
            {"border-style",    new Property("border-style")    { Term = new InitialTerm() }},
            {"border-color",    new Property("border-color")    { Term = new InitialTerm() }},
          };

          foreach (var term in GetEnumerable(style.Term))
          {
            if (term is HtmlColor)
            {
              children["border-color"].Term = term;
            }
            else
            {
              prim = term as PrimitiveTerm;
              if (prim != null)
              {
                if (prim.PrimitiveType == UnitType.Ident)
                {
                  children["border-style"].Term = term;
                }
                else
                {
                  children["border-width"].Term = term;
                }
              }
            }
          }

          foreach (var val in children.Values) yield return val;
          break;
        case "margin":
          terms = GetEnumerable(style.Term).ToList();
          switch (terms.Count)
          {
            case 1:
              yield return new Property("margin-top")    { Term = terms[0] };
              yield return new Property("margin-right")  { Term = terms[0] };
              yield return new Property("margin-bottom") { Term = terms[0] };
              yield return new Property("margin-left")   { Term = terms[0] };
              break;
            case 2:
              yield return new Property("margin-top")    { Term = terms[0] };
              yield return new Property("margin-right")  { Term = terms[1] };
              yield return new Property("margin-bottom") { Term = terms[0] };
              yield return new Property("margin-left")   { Term = terms[1] };
              break;
            case 3:
              yield return new Property("margin-top")    { Term = terms[0] };
              yield return new Property("margin-right")  { Term = terms[1] };
              yield return new Property("margin-bottom") { Term = terms[2] };
              yield return new Property("margin-left")   { Term = terms[1] };
              break;
            case 4:
              yield return new Property("margin-top")    { Term = terms[0] };
              yield return new Property("margin-right")  { Term = terms[1] };
              yield return new Property("margin-bottom") { Term = terms[2] };
              yield return new Property("margin-left")   { Term = terms[3] };
              break;
            default:
              throw new InvalidOperationException();
          }

          break;
        case "padding":
          terms = GetEnumerable(style.Term).ToList();
          switch (terms.Count)
          {
            case 1:
              yield return new Property("padding-top")    { Term = terms[0] };
              yield return new Property("padding-right")  { Term = terms[0] };
              yield return new Property("padding-bottom") { Term = terms[0] };
              yield return new Property("padding-left")   { Term = terms[0] };
              break;
            case 2:
              yield return new Property("padding-top")    { Term = terms[0] };
              yield return new Property("padding-right")  { Term = terms[1] };
              yield return new Property("padding-bottom") { Term = terms[0] };
              yield return new Property("padding-left")   { Term = terms[1] };
              break;
            case 3:
              yield return new Property("padding-top")    { Term = terms[0] };
              yield return new Property("padding-right")  { Term = terms[1] };
              yield return new Property("padding-bottom") { Term = terms[2] };
              yield return new Property("padding-left")   { Term = terms[1] };
              break;
            case 4:
              yield return new Property("padding-top")    { Term = terms[0] };
              yield return new Property("padding-right")  { Term = terms[1] };
              yield return new Property("padding-bottom") { Term = terms[2] };
              yield return new Property("padding-left")   { Term = terms[3] };
              break;
            default:
              throw new InvalidOperationException();
          }

          break;
        case "-webkit-margin-start":
        case "-moz-margin-start":
          if (leftToRight) yield return new Property("margin-left") { Term = style.Term };
          if (!leftToRight) yield return new Property("margin-right") { Term = style.Term };
          break;
        case "-webkit-padding-start":
        case "-moz-padding-start":
          if (leftToRight) yield return new Property("padding-left") { Term = style.Term };
          if (!leftToRight) yield return new Property("padding-right") { Term = style.Term };
          break;
        case "-webkit-margin-end":
        case "-moz-margin-end":
          if (leftToRight) yield return new Property("margin-right") { Term = style.Term };
          if (!leftToRight) yield return new Property("margin-left") { Term = style.Term };
          break;
        case "-webkit-padding-end":
        case "-moz-padding-end":
          if (leftToRight) yield return new Property("padding-right") { Term = style.Term };
          if (!leftToRight) yield return new Property("padding-left") { Term = style.Term };
          break;
        default:
          yield return style;
          break;
      }
    }