├── .gitignore ├── CONTRIBUTING.md ├── ClientLibrary ├── ClientLibrary.sln ├── Common │ ├── ClientError.cs │ └── ClientException.cs ├── Contract │ └── EntityLink.cs ├── EntityLinkingServiceClient.cs ├── IEntityLinkingServiceClient.cs ├── Microsoft.ProjectOxford.EntityLinking.csproj ├── Microsoft.ProjectOxford.EntityLinking.nuspec ├── Properties │ └── AssemblyInfo.cs ├── build_nuget_package.cmd └── packages.config ├── LICENSE-IMAGE.md ├── LICENSE.md ├── README.md └── ThirdPartyNotices.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | *.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.pfx 193 | *.publishsettings 194 | node_modules/ 195 | orleans.codegen.cs 196 | 197 | # Since there are multiple workflows, uncomment next line to ignore bower_components 198 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 199 | #bower_components/ 200 | 201 | # RIA/Silverlight projects 202 | Generated_Code/ 203 | 204 | # Backup & report files from converting an old project file 205 | # to a newer Visual Studio version. Backup files are not needed, 206 | # because we have git ;-) 207 | _UpgradeReport_Files/ 208 | Backup*/ 209 | UpgradeLog*.XML 210 | UpgradeLog*.htm 211 | 212 | # SQL Server files 213 | *.mdf 214 | *.ldf 215 | 216 | # Business Intelligence projects 217 | *.rdl.data 218 | *.bim.layout 219 | *.bim_*.settings 220 | 221 | # Microsoft Fakes 222 | FakesAssemblies/ 223 | 224 | # GhostDoc plugin setting file 225 | *.GhostDoc.xml 226 | 227 | # Node.js Tools for Visual Studio 228 | .ntvs_analysis.dat 229 | 230 | # Visual Studio 6 build log 231 | *.plg 232 | 233 | # Visual Studio 6 workspace options file 234 | *.opt 235 | 236 | # Visual Studio LightSwitch build output 237 | **/*.HTMLClient/GeneratedArtifacts 238 | **/*.DesktopClient/GeneratedArtifacts 239 | **/*.DesktopClient/ModelManifest.xml 240 | **/*.Server/GeneratedArtifacts 241 | **/*.Server/ModelManifest.xml 242 | _Pvt_Extensions 243 | 244 | # Paket dependency manager 245 | .paket/paket.exe 246 | paket-files/ 247 | 248 | # FAKE - F# Make 249 | .fake/ 250 | 251 | # JetBrains Rider 252 | .idea/ 253 | *.sln.iml 254 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to Microsoft Cognitive Services Client Libraries & Samples 2 | =============================================== 3 | So, you want to contribute on a client library or sample for one of the Microsoft Cognitive Services. 4 | Here's what you need to know. 5 | 6 | 1. Each SDK should include both a client library and a sample showing the API in 7 | action 8 | 9 | 2. When working on an SDK, it's important that we are consistent from project to project, so we ask you to follow the coding guidelines below: 10 | 11 | - Windows [(Coding guidelines for C#)](https://msdn.microsoft.com/en-us/library/ff926074.aspx) -- also reference our [common Windows code](https://github.com/Microsoft/Cognitive-common-windows) for building samples 12 | 13 | - Android [(Coding guidelines for 14 | Java)]() 15 | 16 | - iOS Objective-C [(Coding guidelines for 17 | Cocoa)]() 18 | 19 | - Optional: Client Javascript ([Coding guidelines for 20 | npm]()) 21 | 22 | 3. Samples are important for illustrating how to actually call into the API. 23 | Samples should be as visual and reusable as possible. 24 | 25 | - Do: 26 | 27 | - Create a UI sample when possible. 28 | 29 | - Make your sample user friendly. Expect that developers will want to try 30 | different mainline scenarios and key APIs. 31 | 32 | - Create code that's easy for other developers to copy/paste into their 33 | own solutions 34 | 35 | - Consider: 36 | 37 | - Adding UI to allow devs to quickly copy/paste subscription keys, instead 38 | of updating them in the code or using a config file. The 39 | FaceAPI-WPF-Samples.sln provides an example. 40 | 41 | - Don't: 42 | 43 | - Leave your subscription key in the source of samples. You do not want your key to be abused by others. 44 | 45 | Happy coding! 46 | -------------------------------------------------------------------------------- /ClientLibrary/ClientLibrary.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.ProjectOxford.EntityLinking", "Microsoft.ProjectOxford.EntityLinking.csproj", "{A3D16069-B539-471D-B3BF-7B0D4695CEDE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {A3D16069-B539-471D-B3BF-7B0D4695CEDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {A3D16069-B539-471D-B3BF-7B0D4695CEDE}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {A3D16069-B539-471D-B3BF-7B0D4695CEDE}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {A3D16069-B539-471D-B3BF-7B0D4695CEDE}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /ClientLibrary/Common/ClientError.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-EntityLinking-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | 36 | namespace Microsoft.ProjectOxford.Common 37 | { 38 | /// 39 | /// Container of ErrorMessage. 40 | /// 41 | internal class ErrorResponse 42 | { 43 | /// 44 | /// Gets or sets Error. 45 | /// 46 | public ClientError Error { get; set; } 47 | } 48 | /// 49 | /// Client Error message entity. 50 | /// 51 | public class ClientError 52 | { 53 | /// 54 | /// Gets or sets error code in entity. 55 | /// 56 | /// 57 | /// The code of client error. 58 | /// 59 | public string Code 60 | { 61 | get; 62 | set; 63 | } 64 | 65 | /// 66 | /// Gets or sets the message. 67 | /// 68 | /// 69 | /// The message. 70 | /// 71 | public string Message 72 | { 73 | get; 74 | set; 75 | } 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /ClientLibrary/Common/ClientException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-EntityLinking-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Net; 36 | 37 | namespace Microsoft.ProjectOxford.Common 38 | { 39 | /// 40 | /// The Exception will be shown to client. 41 | /// 42 | public class ClientException : Exception 43 | { 44 | /// 45 | /// Initializes a new instance of the class. 46 | /// 47 | public ClientException() 48 | : base() 49 | { 50 | } 51 | 52 | /// 53 | /// Initializes a new instance of the class. 54 | /// 55 | /// The corresponding error message. 56 | public ClientException(string message) 57 | : base(message) 58 | { 59 | this.Error = new ClientError() 60 | { 61 | Code = HttpStatusCode.InternalServerError.ToString(), 62 | Message = message 63 | }; 64 | } 65 | 66 | /// 67 | /// Initializes a new instance of the class. 68 | /// 69 | /// The corresponding error message. 70 | /// The Http Status code. 71 | public ClientException(string message, HttpStatusCode httpStatus) 72 | : base(message) 73 | { 74 | this.HttpStatus = httpStatus; 75 | 76 | this.Error = new ClientError() 77 | { 78 | Code = this.HttpStatus.ToString(), 79 | Message = message 80 | }; 81 | } 82 | 83 | /// 84 | /// Initializes a new instance of the class. 85 | /// 86 | /// The corresponding error message. 87 | /// The inner exception. 88 | public ClientException(string message, Exception innerException) 89 | : base(message, innerException) 90 | { 91 | this.Error = new ClientError() 92 | { 93 | Code = HttpStatusCode.InternalServerError.ToString(), 94 | Message = message 95 | }; 96 | } 97 | 98 | /// 99 | /// Initializes a new instance of the class. 100 | /// 101 | /// The corresponding error message. 102 | /// The error code. 103 | /// The http status. 104 | /// The inner exception. 105 | public ClientException(string message, string errorCode, HttpStatusCode httpStatus, Exception innerException) 106 | : base(message, innerException) 107 | { 108 | this.HttpStatus = httpStatus; 109 | 110 | this.Error = new ClientError() 111 | { 112 | Code = errorCode, 113 | Message = message 114 | }; 115 | } 116 | 117 | /// 118 | /// Initializes a new instance of the class. 119 | /// 120 | /// The error entity. 121 | /// The http status. 122 | public ClientException(ClientError error, HttpStatusCode httpStatus) 123 | { 124 | this.Error = error; 125 | this.HttpStatus = httpStatus; 126 | } 127 | 128 | /// 129 | /// Gets http status of http response. 130 | /// 131 | /// 132 | /// The HTTP status. 133 | /// 134 | public HttpStatusCode HttpStatus { get; private set; } 135 | 136 | /// 137 | /// Gets or sets the httpError message. 138 | /// 139 | /// 140 | /// The error. 141 | /// 142 | public ClientError Error { get; set; } 143 | 144 | /// 145 | /// Create Client Exception of Bad Request. 146 | /// 147 | /// The corresponding error message. 148 | /// Client Exception Instance. 149 | public static ClientException BadRequest(string message) 150 | { 151 | return new ClientException( 152 | new ClientError() 153 | { 154 | Code = ((int)HttpStatusCode.BadRequest).ToString(), 155 | Message = message 156 | }, 157 | HttpStatusCode.BadRequest); 158 | } 159 | } 160 | } -------------------------------------------------------------------------------- /ClientLibrary/Contract/EntityLink.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-EntityLinking-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Collections.Generic; 36 | using System.Linq; 37 | using System.Runtime.Serialization; 38 | using Microsoft.ProjectOxford.Common; 39 | 40 | namespace Microsoft.ProjectOxford.EntityLinking.Contract 41 | { 42 | /// 43 | /// Container of response. 44 | /// 45 | [DataContract] 46 | internal class EntityLinkResponse 47 | { 48 | /// 49 | /// Gets or sets EntityLinks. 50 | /// 51 | [DataMember(EmitDefaultValue = false, Name = "entities")] 52 | public EntityLink[] EntityLinks { get; set; } 53 | } 54 | 55 | /// 56 | /// Represents name of the entity, wikipedia id, matches and score. 57 | /// 58 | [DataContract] 59 | public class EntityLink 60 | { 61 | /// 62 | /// Name of the entity. 63 | /// 64 | [DataMember(Name = "name")] 65 | public string Name { get; set; } 66 | 67 | /// 68 | /// Id of the wikipedia linked entity. 69 | /// 70 | [DataMember(Name = "wikipediaId")] 71 | public string WikipediaID { get; set; } 72 | 73 | /// 74 | /// Matches text of the entity within the given paragraph. 75 | /// 76 | [DataMember(Name = "matches")] 77 | public IList Matches { get; set; } 78 | 79 | /// 80 | /// Confidence score of the linking. 81 | /// 82 | [DataMember(Name = "score")] 83 | public double Score { get; set; } 84 | } 85 | 86 | /// 87 | /// The match text of the knowledge base linked entity. 88 | /// 89 | [DataContract] 90 | public class Match 91 | { 92 | /// 93 | /// The matched text. 94 | /// 95 | [DataMember(Name = "text")] 96 | public string Text { get; set; } 97 | 98 | /// 99 | /// Matched entries within the given paragraph. 100 | /// 101 | [DataMember(Name = "entries")] 102 | public IList Entries { get; set; } 103 | } 104 | 105 | /// 106 | /// Represents the entry offset and score. 107 | /// 108 | [DataContract] 109 | public class Entry 110 | { 111 | /// 112 | /// Offset of the entry. 113 | /// 114 | [DataMember(Name = "offset")] 115 | public int Offset { get; set; } 116 | 117 | /// 118 | /// The score of the entry. 119 | /// 120 | [DataMember(Name = "score")] 121 | public double Score { get; set; } 122 | } 123 | 124 | 125 | } 126 | -------------------------------------------------------------------------------- /ClientLibrary/EntityLinkingServiceClient.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-EntityLinking-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Net.Http; 36 | using System.Text; 37 | using System.Threading.Tasks; 38 | 39 | using Microsoft.ProjectOxford.Common; 40 | using Microsoft.ProjectOxford.EntityLinking.Contract; 41 | using Newtonsoft.Json; 42 | using Newtonsoft.Json.Serialization; 43 | 44 | namespace Microsoft.ProjectOxford.EntityLinking 45 | { 46 | /// 47 | /// The EntityLinking service client proxy implementation. 48 | /// 49 | public class EntityLinkingServiceClient : IEntityLinkingServiceClient 50 | { 51 | #region private members 52 | 53 | /// 54 | /// The json header 55 | /// 56 | private const string Header = "text/plain"; 57 | 58 | /// 59 | /// The subscription key name. 60 | /// 61 | private const string SubscriptionKeyName = "subscription-key"; 62 | 63 | /// 64 | /// Path string for REST EntityLink recognition method. 65 | /// 66 | private const string LinkQuery = "link"; 67 | 68 | /// 69 | /// The subscription key. 70 | /// 71 | private readonly string _subscriptionKey; 72 | 73 | /// 74 | /// The default resolver. 75 | /// 76 | private static CamelCasePropertyNamesContractResolver s_defaultResolver = new CamelCasePropertyNamesContractResolver(); 77 | 78 | private static JsonSerializerSettings s_settings = new JsonSerializerSettings() 79 | { 80 | DateFormatHandling = DateFormatHandling.IsoDateFormat, 81 | NullValueHandling = NullValueHandling.Ignore, 82 | ContractResolver = s_defaultResolver 83 | }; 84 | 85 | private static HttpClient s_httpClient = new HttpClient(); 86 | private readonly HttpClient _httpClient; 87 | 88 | private static string s_apiRoot = "https://westus.api.cognitive.microsoft.com"; 89 | private readonly string _serviceUrl; 90 | #endregion 91 | 92 | /// 93 | /// Initializes a new instance of the class. 94 | /// 95 | /// The subscription key. 96 | public EntityLinkingServiceClient(string subscriptionKey) : this(s_httpClient, subscriptionKey, s_apiRoot) { } 97 | 98 | /// 99 | /// Initializes a new instance of the class. 100 | /// 101 | /// The subscription key. 102 | /// Host name of the service URL, without the trailing slash. 103 | public EntityLinkingServiceClient(string subscriptionKey, string apiRoot) : this(s_httpClient, subscriptionKey, apiRoot) { } 104 | 105 | /// 106 | /// Initializes a new instance of the class, with a client-supplied 107 | /// HttpClient object. Intended primarily for testing. 108 | /// 109 | /// the HttpClient object 110 | /// The subscription key. 111 | public EntityLinkingServiceClient(HttpClient httpClient, string subscriptionKey) : this(httpClient, subscriptionKey, s_apiRoot) { } 112 | 113 | /// 114 | /// Initializes a new instance of the class, with a client-supplied 115 | /// HttpClient object. Intended primarily for testing. 116 | /// 117 | /// the HttpClient object 118 | /// The subscription key. 119 | public EntityLinkingServiceClient(HttpClient httpClient, string subscriptionKey, string apiRoot) 120 | { 121 | _httpClient = httpClient; 122 | _subscriptionKey = subscriptionKey; 123 | _serviceUrl = apiRoot + "/entitylinking/v1.0"; 124 | } 125 | 126 | #region IEntityLinkingServiceClient implementations 127 | 128 | /// 129 | /// Linking entities in a text. 130 | /// 131 | /// the text. 132 | /// the specific word or phrase within the text that is to be entity linked. If not specified, the service will try to recognize and identify all the entities within the input text. 133 | /// the location (in offset by characters) of the selected word or phrase within the input text. Used to distinguish when there are multiple instances of the same words or phrases within the input text. Only valid when the selection is specified. 134 | /// Async task, which, upon completion, will return EntityLinks. 135 | public async Task LinkAsync(string text, string selection="", int offset=0) 136 | { 137 | return await SendRequestAsync(text, selection, offset); 138 | } 139 | 140 | #endregion 141 | 142 | #region the JSON client 143 | /// 144 | /// Helper method executing the REST request. 145 | /// 146 | /// Content of the HTTP request. 147 | /// 148 | private async Task SendRequestAsync(string requestBody, string selection, int offset) 149 | { 150 | var httpMethod = HttpMethod.Post; 151 | var requestUri = new StringBuilder(); 152 | requestUri.AppendFormat("{0}/{1}", _serviceUrl, LinkQuery); 153 | requestUri.Append('?'); 154 | 155 | requestUri.AppendFormat("{0}={1}", SubscriptionKeyName, _subscriptionKey); 156 | 157 | if (!string.IsNullOrEmpty(selection)) 158 | { 159 | requestUri.Append($"&selection={Uri.EscapeDataString(selection)}"); 160 | if (offset > 0) 161 | { 162 | requestUri.Append($"&offset={offset}"); 163 | } 164 | } 165 | 166 | var request = new HttpRequestMessage(httpMethod, _serviceUrl); 167 | request.RequestUri = new Uri(requestUri.ToString()); 168 | 169 | if (requestBody != null) 170 | { 171 | request.Content = new StringContent(requestBody, Encoding.UTF8, Header); 172 | } 173 | 174 | HttpResponseMessage response = await _httpClient.SendAsync(request); 175 | if (response.IsSuccessStatusCode) 176 | { 177 | string responseContent = null; 178 | if (response.Content != null) 179 | { 180 | responseContent = await response.Content.ReadAsStringAsync(); 181 | } 182 | 183 | if (!string.IsNullOrWhiteSpace(responseContent)) 184 | { 185 | var ret = JsonConvert.DeserializeObject(responseContent, s_settings); 186 | return ret?.EntityLinks; 187 | } 188 | 189 | return null; 190 | } 191 | else 192 | { 193 | if (response.Content != null) 194 | { 195 | var errorObjectString = await response.Content.ReadAsStringAsync(); 196 | ErrorResponse errorResponse = JsonConvert.DeserializeObject(errorObjectString); 197 | if (errorResponse?.Error != null) 198 | { 199 | throw new ClientException(errorResponse.Error, response.StatusCode); 200 | } 201 | } 202 | 203 | response.EnsureSuccessStatusCode(); 204 | } 205 | 206 | return null; 207 | } 208 | 209 | 210 | #endregion 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /ClientLibrary/IEntityLinkingServiceClient.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-EntityLinking-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System.IO; 35 | using System.Threading.Tasks; 36 | 37 | using Microsoft.ProjectOxford.Common; 38 | 39 | namespace Microsoft.ProjectOxford.EntityLinking 40 | { 41 | /// 42 | /// The EntityLinking service client proxy interface. 43 | /// 44 | internal interface IEntityLinkingServiceClient 45 | { 46 | /// 47 | /// Linking entities in a text. 48 | /// 49 | /// the text. 50 | /// the specific word or phrase within the text that is to be entity linked. If not specified, the service will try to recognize and identify all the entities within the input text. 51 | /// the location (in offset by characters) of the selected word or phrase within the input text. Used to distinguish when there are multiple instances of the same words or phrases within the input text. Only valid when the selection is specified. 52 | /// Async task, which, upon completion, will return EntityLinks. 53 | Task LinkAsync(string text, string selection = "", int offset = 0); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ClientLibrary/Microsoft.ProjectOxford.EntityLinking.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 11.0 6 | Debug 7 | AnyCPU 8 | {A3D16069-B539-471D-B3BF-7B0D4695CEDE} 9 | Library 10 | Properties 11 | Microsoft.ProjectOxford.EntityLinking 12 | Microsoft.ProjectOxford.EntityLinking 13 | en-US 14 | 512 15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | Profile259 17 | v4.5 18 | 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | packages\Newtonsoft.Json.7.0.1\lib\portable-net45+wp80+win8+wpa81+dnxcore50\Newtonsoft.Json.dll 49 | True 50 | 51 | 52 | packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll 53 | True 54 | 55 | 56 | packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll 57 | True 58 | 59 | 60 | packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll 61 | True 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /ClientLibrary/Microsoft.ProjectOxford.EntityLinking.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | Microsoft 8 | Microsoft 9 | https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/LICENSE.md 10 | https://github.com/Microsoft/ProjectOxford-ClientSDK/tree/master/EntityLinking 11 | https://portalstoragewu.blob.core.windows.net/media/Default/Media/ELIS/Large_knowledge_els.png 12 | true 13 | $description$ 14 | This client library allows the use of Microsoft's state-of-the-art cloud-based algorithms to recognize EntityLinkings. See https://github.com/Microsoft/ProjectOxford-ClientSDK/tree/master/EntityLinking for more information. 15 | Update API root. 16 | Copyright (c) 2017 17 | Microsoft Project Oxford EntityLinking 18 | 19 | 20 | -------------------------------------------------------------------------------- /ClientLibrary/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-EntityLinking-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System.Reflection; 35 | using System.Runtime.CompilerServices; 36 | using System.Runtime.InteropServices; 37 | 38 | // General Information about an assembly is controlled through the following 39 | // set of attributes. Change these attribute values to modify the information 40 | // associated with an assembly. 41 | [assembly: AssemblyTitle("Microsoft.ProjectOxford.EntityLinking")] 42 | [assembly: AssemblyDescription("Microsoft Project Oxford Entity Linking Client Library")] 43 | [assembly: AssemblyConfiguration("")] 44 | [assembly: AssemblyCompany("Microsoft Corporation")] 45 | [assembly: AssemblyProduct("Microsoft ProjectOxford")] 46 | [assembly: AssemblyCopyright("Copyright (c) 2017")] 47 | [assembly: AssemblyTrademark("")] 48 | [assembly: AssemblyCulture("")] 49 | 50 | // Setting ComVisible to false makes the types in this assembly not visible 51 | // to COM components. If you need to access a type in this assembly from 52 | // COM, set the ComVisible attribute to true on that type. 53 | [assembly: ComVisible(false)] 54 | 55 | // Version information for an assembly consists of the following four values: 56 | // 57 | // Major Version 58 | // Minor Version 59 | // Build Number 60 | // Revision 61 | // 62 | // You can specify all the values or you can default the Build and Revision Numbers 63 | // by using the '*' as shown below: 64 | // [assembly: AssemblyVersion("1.0.*")] 65 | [assembly: AssemblyVersion("1.0.1.0")] 66 | [assembly: AssemblyFileVersion("1.0.1.0")] 67 | -------------------------------------------------------------------------------- /ClientLibrary/build_nuget_package.cmd: -------------------------------------------------------------------------------- 1 | rem NOTE NOTE Copy the signed DLL into obj\release folder before running this command 2 | nuget pack Microsoft.ProjectOxford.EntityLinking.csproj -Build -OutputDirectory bin\release -Properties Configuration=Release;Platform=AnyCPU -------------------------------------------------------------------------------- /ClientLibrary/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /LICENSE-IMAGE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation 2 | 3 | All rights reserved. 4 | 5 | Microsoft Cognitive Services Client SDK License for Sample Image 6 | 7 | *This license applies only to the sample images. The SDK code is licensed separately, please refer to [LICENSE]()* 8 | 9 | Microsoft may make sample images available in connection with the SDK for the purposes of illustrating the operation of Microsoft Cognitive Services (https://www.microsoft.com/cognitive-services). If no separate license terms are provided with the images, Microsoft grants you a personal, nonexclusive, revocable, royalty-free right to use the images solely within your organization to test the operation of Microsoft Cognitive Services, provided that you agree to indemnify, hold harmless, and defend Microsoft and its suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the images. Except as expressly provided in this section you have no license to modify or distribute the images. 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Microsoft Cognitive Services SDK 2 | 3 | Copyright (c) Microsoft Corporation 4 | 5 | All rights reserved. 6 | 7 | *This license applies only to the SDK code. Sample images are licensed separately, please refer to [LICENSE-IMAGE]()* 8 | 9 | MIT License 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Microsoft Entity Linking Intelligence Service: Windows Client Library & Sample 2 | This repo contains the Windows client library for the Microsoft Entity Linking Intelligence Service, an offering within [Microsoft Cognitive Services](https://www.microsoft.com/cognitive-services), formerly known as Project Oxford. 3 | * [Learn about the Entity Linking Intelligence Service](https://www.microsoft.com/cognitive-services/en-us/entity-linking-intelligence-service) 4 | * [Read the documentation](https://www.microsoft.com/cognitive-services/en-us/entitylinking-api/documentation/overview) 5 | * [Find more SDKs & Samples](https://www.microsoft.com/cognitive-services/en-us/SDK-Sample?api=entity%20linking) 6 | 7 | 8 | ## Contributing 9 | We welcome contributions. Feel free to file issues and pull requests on the repo and we'll address them as we can. Learn more about how you can help on our [Contribution Rules & Guidelines](). 10 | 11 | You can reach out to us anytime with questions and suggestions using our communities below: 12 | - **Support questions:** [StackOverflow]() 13 | - **Feedback & feature requests:** [Cognitive Services UserVoice Forum]() 14 | 15 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 16 | 17 | 18 | ## License 19 | All Microsoft Cognitive Services SDKs and samples are licensed with the MIT License. For more details, see 20 | [LICENSE](). 21 | 22 | Sample images are licensed separately, please refer to [LICENSE-IMAGE](). 23 | 24 | ## Developer Code of Conduct 25 | Developers using Cognitive Services, including this client library & sample, are expected to follow the “Developer Code of Conduct for Microsoft Cognitive Services”, found at [http://go.microsoft.com/fwlink/?LinkId=698895](http://go.microsoft.com/fwlink/?LinkId=698895). 26 | -------------------------------------------------------------------------------- /ThirdPartyNotices.txt: -------------------------------------------------------------------------------- 1 | THIRD-PARTY SOFTWARE NOTICES AND INFORMATION 2 | Do Not Translate or Localize 3 | 4 | This project incorporates components from the projects listed below. The original copyright notices 5 | and licenses under which Microsoft received such components are set forth below. Microsoft reserves all rights not 6 | expressly granted herein, whether by implication, estoppel or otherwise. 7 | 8 | 9 | 1. newtonsoft.json version 8.0.2 (https://github.com/JamesNK/Newtonsoft.Json) 10 | 11 | %% newtonsoft.json NOTICES AND INFORMATION BEGIN HERE 12 | ========================================= 13 | The MIT License (MIT) 14 | 15 | Copyright (c) 2007 James Newton-King 16 | 17 | Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | this software and associated documentation files (the "Software"), to deal in 19 | the Software without restriction, including without limitation the rights to 20 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | the Software, and to permit persons to whom the Software is furnished to do so, 22 | subject to the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be included in all 25 | copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | ========================================= 34 | END OF newtonsoft.json NOTICES AND INFORMATION 35 | --------------------------------------------------------------------------------