From 5096630991840c2886e1c37bdf15de8080b9dbb9 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 15 Apr 2017 18:45:49 -0500 Subject: [PATCH] Pulls back pref labels. --- .gitignore | 289 +++++++++++++++++++++++++++ csharp/ncbo/ncbo.sln | 22 ++ csharp/ncbo/ncbo/Common/Network.cs | 32 +++ csharp/ncbo/ncbo/DataTypes/Ontology.cs | 23 +++ csharp/ncbo/ncbo/DataTypes/OntologyLink.cs | 45 +++++ csharp/ncbo/ncbo/DataTypes/Page.cs | 25 +++ csharp/ncbo/ncbo/DataTypes/PageCollection.cs | 25 +++ csharp/ncbo/ncbo/DataTypes/PageLink.cs | 15 ++ csharp/ncbo/ncbo/GetLabels.cs | 51 +++++ csharp/ncbo/ncbo/Program.cs | 17 ++ csharp/ncbo/ncbo/TextFile1.txt | 11 + csharp/ncbo/ncbo/ncbo.csproj | 18 ++ 12 files changed, 573 insertions(+) create mode 100644 csharp/ncbo/ncbo.sln create mode 100644 csharp/ncbo/ncbo/Common/Network.cs create mode 100644 csharp/ncbo/ncbo/DataTypes/Ontology.cs create mode 100644 csharp/ncbo/ncbo/DataTypes/OntologyLink.cs create mode 100644 csharp/ncbo/ncbo/DataTypes/Page.cs create mode 100644 csharp/ncbo/ncbo/DataTypes/PageCollection.cs create mode 100644 csharp/ncbo/ncbo/DataTypes/PageLink.cs create mode 100644 csharp/ncbo/ncbo/GetLabels.cs create mode 100644 csharp/ncbo/ncbo/Program.cs create mode 100644 csharp/ncbo/ncbo/TextFile1.txt create mode 100644 csharp/ncbo/ncbo/ncbo.csproj diff --git a/.gitignore b/.gitignore index fab6527..d53e491 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,292 @@ java/nbproject/* # IntelliJ java/.idea/* java/*.iml + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs diff --git a/csharp/ncbo/ncbo.sln b/csharp/ncbo/ncbo.sln new file mode 100644 index 0000000..c5fcd42 --- /dev/null +++ b/csharp/ncbo/ncbo.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ncbo", "ncbo\ncbo.csproj", "{AC37CC07-66F9-4F08-A5A4-B65316598005}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AC37CC07-66F9-4F08-A5A4-B65316598005}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC37CC07-66F9-4F08-A5A4-B65316598005}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC37CC07-66F9-4F08-A5A4-B65316598005}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC37CC07-66F9-4F08-A5A4-B65316598005}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/csharp/ncbo/ncbo/Common/Network.cs b/csharp/ncbo/ncbo/Common/Network.cs new file mode 100644 index 0000000..bb035bf --- /dev/null +++ b/csharp/ncbo/ncbo/Common/Network.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace ncbo.Common +{ + public static class Network + { + public static string GetJsonResponse(string url) + { + HttpClient web = new HttpClient(); + web.DefaultRequestHeaders.Add("Authorization", "apikey token=5cddf159-a650-4458-b802-cb5936567668"); + Task asyncResponse = web.GetAsync(url); + asyncResponse.Wait(); + HttpResponseMessage response = asyncResponse.Result; + + Task asyncString = response.Content.ReadAsStringAsync(); + asyncString.Wait(); + + return asyncString.Result; + } + + public static T GetResponseAs(string url) + { + string jsonResponse = GetJsonResponse(url); + return JsonConvert.DeserializeObject(jsonResponse); + } + } +} diff --git a/csharp/ncbo/ncbo/DataTypes/Ontology.cs b/csharp/ncbo/ncbo/DataTypes/Ontology.cs new file mode 100644 index 0000000..1c41352 --- /dev/null +++ b/csharp/ncbo/ncbo/DataTypes/Ontology.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class Ontology + { + [JsonProperty("administeredBy")] + public string[] AdministeredBy { get; set; } + [JsonProperty("acronym")] + public string Acronym { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("summaryOnly")] + public string SummaryOnly { get; set; } + [JsonProperty("ontologyType")] + public string OntologyType { get; set; } + [JsonProperty("links")] + public OntologyLink Links { get; set; } + } +} diff --git a/csharp/ncbo/ncbo/DataTypes/OntologyLink.cs b/csharp/ncbo/ncbo/DataTypes/OntologyLink.cs new file mode 100644 index 0000000..97b6bd6 --- /dev/null +++ b/csharp/ncbo/ncbo/DataTypes/OntologyLink.cs @@ -0,0 +1,45 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class OntologyLink + { + [JsonProperty("submissions")] + public string Submissions { get; set; } + [JsonProperty("properties")] + public string Properties { get; set; } + [JsonProperty("classes")] + public string Classes { get; set; } + [JsonProperty("single_class")] + public string SingleClass { get; set; } + [JsonProperty("roots")] + public string Roots { get; set; } + [JsonProperty("instances")] + public string Instances { get; set; } + [JsonProperty("metrics")] + public string Metrics { get; set; } + [JsonProperty("reviews")] + public string Reviews { get; set; } + [JsonProperty("notes")] + public string Notes { get; set; } + [JsonProperty("groups")] + public string Groups { get; set; } + [JsonProperty("categories")] + public string Categories { get; set; } + [JsonProperty("latest_submission")] + public string LatestSubmission { get; set; } + [JsonProperty("projects")] + public string Projects { get; set; } + [JsonProperty("download")] + public string Download { get; set; } + [JsonProperty("views")] + public string Views { get; set; } + [JsonProperty("analytics")] + public string Analytics { get; set; } + [JsonProperty("ui")] + public string UI { get; set; } + } +} diff --git a/csharp/ncbo/ncbo/DataTypes/Page.cs b/csharp/ncbo/ncbo/DataTypes/Page.cs new file mode 100644 index 0000000..87bd0d4 --- /dev/null +++ b/csharp/ncbo/ncbo/DataTypes/Page.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class Page + { + [JsonProperty("page")] + public int PageNumber { get; set; } + [JsonProperty("pageCount")] + public int PageCount { get; set; } + [JsonProperty("totalCount")] + public int TotalCount { get; set; } + [JsonProperty("prevPage")] + public string PrevPage { get; set; } + [JsonProperty("nextPage")] + public int? NextPageNumber { get; set; } + [JsonProperty("links")] + public PageLink Link { get; set; } + [JsonProperty("collection")] + public List Collections { get; set; } + } +} diff --git a/csharp/ncbo/ncbo/DataTypes/PageCollection.cs b/csharp/ncbo/ncbo/DataTypes/PageCollection.cs new file mode 100644 index 0000000..c6962e2 --- /dev/null +++ b/csharp/ncbo/ncbo/DataTypes/PageCollection.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class PageCollection + { + [JsonProperty("prefLabel")] + public string PrefLabel { get; set; } + [JsonProperty("synonym")] + public List Synonym { get; set; } + [JsonProperty("definition")] + public List Definition { get; set; } + [JsonProperty("cui")] + public List CUI { get; set; } + [JsonProperty("semanticType")] + public List SemanticType { get; set; } + [JsonProperty("obsolete")] + public bool Obsolete { get; set; } + [JsonProperty("links")] + public PageLink Links { get; set; } +} +} diff --git a/csharp/ncbo/ncbo/DataTypes/PageLink.cs b/csharp/ncbo/ncbo/DataTypes/PageLink.cs new file mode 100644 index 0000000..f939d5f --- /dev/null +++ b/csharp/ncbo/ncbo/DataTypes/PageLink.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class PageLink + { + [JsonProperty("nextPage")] + public string NextPageUrl { get; set; } + [JsonProperty("prevPage")] + public string PrevPageUrl { get; set; } + } +} diff --git a/csharp/ncbo/ncbo/GetLabels.cs b/csharp/ncbo/ncbo/GetLabels.cs new file mode 100644 index 0000000..b0b0f58 --- /dev/null +++ b/csharp/ncbo/ncbo/GetLabels.cs @@ -0,0 +1,51 @@ +using ncbo.Common; +using ncbo.DataTypes; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; +using System.Linq; + +namespace ncbo +{ + public static class GetLabels + { + public static void DoIt() + { + // Get all ontologies from the REST service and parse the JSON + Ontology[] ontology = Network.GetResponseAs("http://data.bioontology.org/ontologies"); + + Ontology broOntology = ontology.Where(n => n.Acronym == "BRO").FirstOrDefault(); + + string classesPageUrl = broOntology.Links.Classes; + + Page page = Network.GetResponseAs(classesPageUrl); + + List labels = new List(); + for(;;) + { + string nextPageUrl = page.Link.NextPageUrl; + foreach(PageCollection collection in page.Collections) + { + labels.Add(collection.PrefLabel); + } + + if(!string.IsNullOrEmpty(nextPageUrl)) + { + page = Network.GetResponseAs(nextPageUrl); + } + else + { + break; + } + } + + foreach(string label in labels) + { + Console.WriteLine(label); + } + + Console.ReadLine(); + } + } +} diff --git a/csharp/ncbo/ncbo/Program.cs b/csharp/ncbo/ncbo/Program.cs new file mode 100644 index 0000000..eba2720 --- /dev/null +++ b/csharp/ncbo/ncbo/Program.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; + +namespace ncbo +{ + class Program + { + static void Main(string[] args) + { + GetLabels.DoIt(); + } + } +} \ No newline at end of file diff --git a/csharp/ncbo/ncbo/TextFile1.txt b/csharp/ncbo/ncbo/TextFile1.txt new file mode 100644 index 0000000..470e6bc --- /dev/null +++ b/csharp/ncbo/ncbo/TextFile1.txt @@ -0,0 +1,11 @@ +{"menu": { + "id": "file", + "value": "File", + "popup": { + "menuitem": [ + {"value": "New", "onclick": "CreateNewDoc()"}, + {"value": "Open", "onclick": "OpenDoc()"}, + {"value": "Close", "onclick": "CloseDoc()"} + ] + } +}} \ No newline at end of file diff --git a/csharp/ncbo/ncbo/ncbo.csproj b/csharp/ncbo/ncbo/ncbo.csproj new file mode 100644 index 0000000..fb211d3 --- /dev/null +++ b/csharp/ncbo/ncbo/ncbo.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp1.1 + + + + + + + + + Always + + + + \ No newline at end of file