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.sln b/csharp/ncbo.sln new file mode 100644 index 0000000..c5fcd42 --- /dev/null +++ b/csharp/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/AnnotateText.cs b/csharp/ncbo/AnnotateText.cs new file mode 100644 index 0000000..9d2d7d4 --- /dev/null +++ b/csharp/ncbo/AnnotateText.cs @@ -0,0 +1,64 @@ +using ncbo.Common; +using System; +using System.Collections.Generic; +using System.Text; +using ncbo.DataTypes; + +namespace ncbo +{ + public static class AnnotateText + { + private static void PrintAnnotations(AnnotationResult[] annotationResults) + { + foreach(AnnotationResult annotationResult in annotationResults) + { + AnnotationPage annotationPage = + Network.GetResponseAs(annotationResult.AnnotatedClass.Link.Self); + + Console.WriteLine("Class details"); + Console.WriteLine("\tID: " + annotationPage.ID); + Console.WriteLine("\tPrefLabel: " + annotationPage.PrefLabel); + Console.WriteLine("\tOntology: " + annotationPage.Links?.Ontology); + + Console.WriteLine("Annotation details"); + foreach(Annotation annotation in annotationResult.Annotations) + { + Console.WriteLine("\tFrom: " + annotation.From); + Console.WriteLine("\tTo: " + annotation.To); + Console.WriteLine("\tMatch type: " + annotation.MatchType); + } + + if(annotationResult.Hierarchy!=null && annotationResult.Hierarchy.Count > 0) + { + Console.WriteLine("Hierachy Annotations"); + foreach (AnnotatedClass annotatedClass in annotationResult.Hierarchy) + { + AnnotationPage annotationHierarchyPage = + Network.GetResponseAs(annotationResult.AnnotatedClass.Link.Self); + + Console.WriteLine("\tClass details"); + Console.WriteLine("\t\tID: " + annotationHierarchyPage.ID); + Console.WriteLine("\t\tPrefLabel: " + annotationHierarchyPage.PrefLabel); + Console.WriteLine("\t\tOntology: " + annotationHierarchyPage.Links.Ontology); + Console.WriteLine("\t\tDistance from originally annotated class: : " + annotatedClass.Distance); + } + } + + Console.WriteLine("===="); + } + } + + public static void DoIt() + { + string textToAnnotate = + "Melanoma is a malignant tumor of melanocytes which are found " + + "predominantly in skin but also in the bowel and the eye."; + + AnnotationResult[] annotationResults = + Network.GetResponseAs(Constants.BaseUrl + "/annotator?text=" + textToAnnotate); + + PrintAnnotations(annotationResults); + } + } +} + \ No newline at end of file diff --git a/csharp/ncbo/ClassesSearch.cs b/csharp/ncbo/ClassesSearch.cs new file mode 100644 index 0000000..b5d28ed --- /dev/null +++ b/csharp/ncbo/ClassesSearch.cs @@ -0,0 +1,35 @@ +using ncbo.Common; +using ncbo.DataTypes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace ncbo +{ + public static class ClassesSearch + { + public static void DoIt() + { + string[] lines = File.ReadAllLines("classes_search_terms.txt"); + + List allCollections = new List(); + foreach(string line in lines) + { + Page page = + Network.GetResponseAs("http://data.bioontology.org/search?q=" + line); + + foreach(PageCollection collection in page.Collections) + { + allCollections.Add(collection); + } + } + + foreach(PageCollection collection in allCollections) + { + Console.WriteLine(collection.ID); + } + return; + } + } +} diff --git a/csharp/ncbo/Common/Constants.cs b/csharp/ncbo/Common/Constants.cs new file mode 100644 index 0000000..64630d7 --- /dev/null +++ b/csharp/ncbo/Common/Constants.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.Common +{ + public static class Constants + { + public static string BaseUrl = "http://data.bioontology.org"; + } +} diff --git a/csharp/ncbo/Common/Network.cs b/csharp/ncbo/Common/Network.cs new file mode 100644 index 0000000..bb035bf --- /dev/null +++ b/csharp/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/DataTypes/AnnotatedClass.cs b/csharp/ncbo/DataTypes/AnnotatedClass.cs new file mode 100644 index 0000000..919f190 --- /dev/null +++ b/csharp/ncbo/DataTypes/AnnotatedClass.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class AnnotatedClass + { + [JsonProperty("links")] + public AnnotationLinks Link { get; set; } + [JsonProperty("distance")] + public int Distance { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/Annotation.cs b/csharp/ncbo/DataTypes/Annotation.cs new file mode 100644 index 0000000..47709c2 --- /dev/null +++ b/csharp/ncbo/DataTypes/Annotation.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class Annotation + { + [JsonProperty("from")] + public int From { get; set; } + [JsonProperty("to")] + public int To { get; set; } + [JsonProperty("matchType")] + public string MatchType { get; set; } + [JsonProperty("text")] + public string Text { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/AnnotationCollection.cs b/csharp/ncbo/DataTypes/AnnotationCollection.cs new file mode 100644 index 0000000..2717ba4 --- /dev/null +++ b/csharp/ncbo/DataTypes/AnnotationCollection.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class AnnotationPage + { + [JsonProperty("@id")] + public string ID { get; set; } + [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 AnnotationLinks Links { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/AnnotationLinks.cs b/csharp/ncbo/DataTypes/AnnotationLinks.cs new file mode 100644 index 0000000..e7fb1bc --- /dev/null +++ b/csharp/ncbo/DataTypes/AnnotationLinks.cs @@ -0,0 +1,30 @@ +using Newtonsoft.Json; + +namespace ncbo.DataTypes +{ + public class AnnotationLinks + { + [JsonProperty("self")] + public string Self { get; set; } + [JsonProperty("ontology")] + public string Ontology { get; set; } + [JsonProperty("children")] + public string Children { get; set; } + [JsonProperty("parents")] + public string Parents { get; set; } + [JsonProperty("descendants")] + public string Descendants { get; set; } + [JsonProperty("ancestors")] + public string Ancestors { get; set; } + [JsonProperty("instances")] + public string Instances { get; set; } + [JsonProperty("tree")] + public string Tree { get; set; } + [JsonProperty("notes")] + public string Notes { get; set; } + [JsonProperty("mappings")] + public string Mappings { get; set; } + [JsonProperty("ui")] + public string UI { get; set; } + } +} \ No newline at end of file diff --git a/csharp/ncbo/DataTypes/AnnotationResult.cs b/csharp/ncbo/DataTypes/AnnotationResult.cs new file mode 100644 index 0000000..3589ec0 --- /dev/null +++ b/csharp/ncbo/DataTypes/AnnotationResult.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class AnnotationResult + { + [JsonProperty("annotatedClass")] + public AnnotatedClass AnnotatedClass { get; set; } + [JsonProperty("hierarchy")] + public List Hierarchy { get; set; } + [JsonProperty("annotations")] + public List Annotations { get; set; } + [JsonProperty("mappings")] + public List Mappings { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/Ontology.cs b/csharp/ncbo/DataTypes/Ontology.cs new file mode 100644 index 0000000..5cd1de2 --- /dev/null +++ b/csharp/ncbo/DataTypes/Ontology.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class Ontology + { + [JsonProperty("@id")] + public string ID { get; set; } + [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/DataTypes/OntologyLink.cs b/csharp/ncbo/DataTypes/OntologyLink.cs new file mode 100644 index 0000000..97b6bd6 --- /dev/null +++ b/csharp/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/DataTypes/Page.cs b/csharp/ncbo/DataTypes/Page.cs new file mode 100644 index 0000000..cc83b6b --- /dev/null +++ b/csharp/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 PageLinks Link { get; set; } + [JsonProperty("collection")] + public List Collections { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/PageCollection.cs b/csharp/ncbo/DataTypes/PageCollection.cs new file mode 100644 index 0000000..7924224 --- /dev/null +++ b/csharp/ncbo/DataTypes/PageCollection.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class PageCollection + { + [JsonProperty("@id")] + public string ID { get; set; } + [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 PageLinks Links { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/PageLink.cs b/csharp/ncbo/DataTypes/PageLink.cs new file mode 100644 index 0000000..8f0aff8 --- /dev/null +++ b/csharp/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 PageLinks + { + [JsonProperty("nextPage")] + public string NextPageUrl { get; set; } + [JsonProperty("prevPage")] + public string PrevPageUrl { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/ResourceContext.cs b/csharp/ncbo/DataTypes/ResourceContext.cs new file mode 100644 index 0000000..99aec31 --- /dev/null +++ b/csharp/ncbo/DataTypes/ResourceContext.cs @@ -0,0 +1,39 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class ResourceContext + { + [JsonProperty("submissions")] + public string Submissions { get; set; } + [JsonProperty("notes")] + public string Notes { get; set; } + [JsonProperty("categories")] + public string Categories { get; set; } + [JsonProperty("provisional_classes")] + public string ProvisionalClasses { get; set; } + [JsonProperty("slices")] + public string Slices { get; set; } + [JsonProperty("metrics")] + public string Metrics { get; set; } + [JsonProperty("mappings")] + public string Mappings { get; set; } + [JsonProperty("users")] + public string Users { get; set; } + [JsonProperty("projects")] + public string Projects { get; set; } + [JsonProperty("ontologies")] + public string Ontologies { get; set; } + [JsonProperty("groups")] + public string Groups { get; set; } + [JsonProperty("replies")] + public string Replies { get; set; } + [JsonProperty("provisional_relations")] + public string ProvisionalRelations { get; set; } + [JsonProperty("reviews")] + public string Reviews { get; set; } + } +} diff --git a/csharp/ncbo/DataTypes/ResourceLinks.cs b/csharp/ncbo/DataTypes/ResourceLinks.cs new file mode 100644 index 0000000..d6cb1a2 --- /dev/null +++ b/csharp/ncbo/DataTypes/ResourceLinks.cs @@ -0,0 +1,59 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class ResourceLinks + { + [JsonProperty("submissions")] + public string Submissions { get; set; } + [JsonProperty("notes")] + public string Notes { get; set; } + [JsonProperty("categories")] + public string Categories { get; set; } + [JsonProperty("provisional_classes")] + public string ProvisionalClasses { get; set; } + [JsonProperty("annotator")] + public string Annotator { get; set; } + [JsonProperty("resource_index")] + public string ResourceIndex { get; set; } + [JsonProperty("documentation")] + public string Documentation { get; set; } + [JsonProperty("slices")] + public string Slices { get; set; } + [JsonProperty("metrics")] + public string Metrics { get; set; } + [JsonProperty("mappings")] + public string Mappings { get; set; } + [JsonProperty("users")] + public string Users { get; set; } + [JsonProperty("search")] + public string Search { get; set; } + [JsonProperty("projects")] + public string Projects { get; set; } + [JsonProperty("ontologies")] + public string Ontologies { get; set; } + [JsonProperty("ccv")] + public string CCV { get; set; } + [JsonProperty("recommender")] + public string Recommender { get; set; } + [JsonProperty("groups")] + public string Groups { get; set; } + [JsonProperty("replies")] + public string Replies { get; set; } + [JsonProperty("recommender_v1")] + public string RecommenderV1 { get; set; } + [JsonProperty("provisional_relations")] + public string ProvisionalRelations { get; set; } + [JsonProperty("property_search")] + public string PropertySearch { get; set; } + [JsonProperty("analytics")] + public string Analytics { get; set; } + [JsonProperty("reviews")] + public string Reviews { get; set; } + [JsonProperty("@context")] + public ResourceContext Context { get; set; } +} +} diff --git a/csharp/ncbo/DataTypes/Resources.cs b/csharp/ncbo/DataTypes/Resources.cs new file mode 100644 index 0000000..16bfc53 --- /dev/null +++ b/csharp/ncbo/DataTypes/Resources.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ncbo.DataTypes +{ + public class Resources + { + [JsonProperty("links")] + public ResourceLinks Links { get; set; } + } +} diff --git a/csharp/ncbo/GetLabels.cs b/csharp/ncbo/GetLabels.cs new file mode 100644 index 0000000..8a232b4 --- /dev/null +++ b/csharp/ncbo/GetLabels.cs @@ -0,0 +1,49 @@ +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(Constants.BaseUrl + "/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); + } + } + } +} diff --git a/csharp/ncbo/ListOntologies.cs b/csharp/ncbo/ListOntologies.cs new file mode 100644 index 0000000..fd7a8b2 --- /dev/null +++ b/csharp/ncbo/ListOntologies.cs @@ -0,0 +1,27 @@ +using ncbo.Common; +using ncbo.DataTypes; +using System; +using System.Collections.Generic; +using System.Text; +using System.Linq; + +namespace ncbo +{ + public static class ListOntologies + { + public static void DoIt() + { + Resources resources = Network.GetResponseAs("http://data.bioontology.org"); + + Ontology[] ontologies = Network.GetResponseAs(resources.Links.Ontologies); + + IEnumerable ontologyStrings = ontologies.Select(n => n.Name + Environment.NewLine + + n.ID + Environment.NewLine + Environment.NewLine); + + foreach(string ontologyString in ontologyStrings) + { + Console.WriteLine(ontologyString); + } + } + } +} diff --git a/csharp/ncbo/Program.cs b/csharp/ncbo/Program.cs new file mode 100644 index 0000000..2b5341e --- /dev/null +++ b/csharp/ncbo/Program.cs @@ -0,0 +1,33 @@ +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) + { + Console.WriteLine("GetLabels:"); + GetLabels.DoIt(); + + Console.WriteLine(); + Console.WriteLine("AnnotateText:"); + AnnotateText.DoIt(); + + Console.WriteLine(); + Console.WriteLine("ClassesSearch"); + ClassesSearch.DoIt(); + + Console.WriteLine(); + Console.WriteLine("ListOntologies"); + ListOntologies.DoIt(); + + Console.WriteLine("Done"); + Console.ReadLine(); + } + } +} \ No newline at end of file diff --git a/csharp/ncbo/classes_search_terms.txt b/csharp/ncbo/classes_search_terms.txt new file mode 100644 index 0000000..3bfddd9 --- /dev/null +++ b/csharp/ncbo/classes_search_terms.txt @@ -0,0 +1,6 @@ +heart +lung +experiment +human +brain +melanoma \ No newline at end of file diff --git a/csharp/ncbo/ncbo.csproj b/csharp/ncbo/ncbo.csproj new file mode 100644 index 0000000..b248623 --- /dev/null +++ b/csharp/ncbo/ncbo.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp1.1 + + + + + + + + + Always + + + + \ No newline at end of file