npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@myrmidon/cadmus-refs-dbpedia-lookup

v5.1.1

Published

Cadmus - DBPedia lookup.

Downloads

181

Readme

CadmusRefsDbpediaLookup

📦 npm i @myrmidon/cadmus-refs-dbpedia-lookup

This library was generated with Angular CLI version 17.3.0.

DBPedia lookup is currently limited to the DBPedia API keyword lookup. You can configure this service via DbediaOptions, which provides the following properties:

  • searchUri: the search function URI. Default is https://lookup.dbpedia.org/api/search.
  • prefixUri: the prefix lookup function URI. Default is https://lookup.dbpedia.org/api/prefix.
  • limit (default=10): the maximum number of documents in result. AFAIK the DBPedia service does not provide paging via an offset, so this is the only available option here.
  • prefix (default=true): true for a prefix lookup (=match the beginning of the input string, rather than the whole input string).
  • types: the types filters. These are one or more DBpedia classes from the DBpedia ontology that the results should have. Using this parameter will only retrieve resources of the passed type(s). For instance, you might want to use http://dbpedia.org/ontology/Person for persons, http://dbpedia.org/ontology/Place for places, etc.

Essential types from DBPedia ontology:

Main properties:

  • docs (array):
    • resource: array with (usually a single?) DBPedia URI.
    • label: array with (usually a single?) string.
    • type: array with DBPedia ontology types (you can use typeName to get their user friendly names, which are just the last token in the corresponding type URI).
    • category: array with DBPedia category URIs.
    • comment: array with comment.

Note that all the values may include <B></B> for bold, and presumably also <I> and <U>.

Usage

Should your DBPedia endpoint not support CORS nor JSONP, you can use a proxy as follows:

(1) in your backend API, add a proxy API controller like this (ProxyController.cs):

[ApiController]
[Route("api/proxy")]
public sealed class ProxyController : ControllerBase
{
    private readonly HttpClient _httpClient;

    public ProxyController(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    /// <summary>
    /// Gets the response from the specified URI.
    /// </summary>
    /// <param name="uri">The URI, e.g.
    /// <c>https://lookup.dbpedia.org/api/search?query=plato&format=json&maxResults=10</c>
    /// .</param>
    /// <returns>Response.</returns>
    [HttpGet]
    [ResponseCache(Duration = 60 * 10, VaryByQueryKeys = ["uri"], NoStore = false)]
    public async Task<IActionResult> Get([FromQuery] string uri)
    {
        try
        {
            HttpResponseMessage response = await _httpClient.GetAsync(uri);

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content
                    .ReadAsStringAsync();
                return Content(content, "application/json");
            }

            return StatusCode((int)response.StatusCode);
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.ToString());
            return StatusCode(500, ex.Message);
        }
    }
}

This requires CORS, which should already be setup for the API, and the following services:

builder.Services.AddHttpClient();
// for caching
builder.Services.AddResponseCaching();

If you are not using response caching (i.e. you remove the ResponseCacheAttribute from the sample code above) you can remove AddResponseCaching.

Also, if you use response caching (which is the default) add this middleware to your app's pipeline (immediately after CORS):

app.UseResponseCaching();

(2) Once you provide this proxy endpoint, configure the Angular app like this:

{ provide: HTTP_INTERCEPTORS, useClass: ProxyInterceptor, multi: true },
{ provide: PROXY_INTERCEPTOR_OPTIONS, useValue: {
    proxyUrl: 'http://localhost:5161/api/proxy',
    urls: [
      'http://lookup.dbpedia.org/api/search',
      'http://lookup.dbpedia.org/api/prefix'
    ]
  }
},

This configures the proxy interceptor, whose task is intercepting requests to services not supporting CORS, like DBPedia, and rewrite them so that they are redirected to the proxy service endpoint shown above under (1). Using a proxy bypasses the issues of browsers in consuming services not providing support for CORS or JSONP.