Git Product home page Git Product logo

curies4j's Introduction

curies4j

A Java implementation of the curies Python package, which enables idiomatic conversion between URIs and compact URIs (CURIEs).

Note that this package returns null when it gets content it can't handle instead of throwing errors.

import org.biopragmatics.curies.Converter;
import org.biopragmatics.curies.Reference;

class CuriesDemo1 {
    public static void main(String[] args) {
        Converter converter = Converter.getExampleConverter();

        String curie = "CHEBI:1234";
        String uri = "http://purl.obolibrary.org/obo/CHEBI_1234";

        String reference = new Reference("CHEBI", "1234");
        String prefix = reference.getPrefix();  // "CHEBI"
        String identifier = reference.getIdentfier();  // "1234"

        // 2 ways to expand a CURIE into a URI
        String uri1 = converter.expand("CHEBI:1234");
        String uri2 = converter.expand("CHEBI", "1234");
        // "http://purl.obolibrary.org/obo/CHEBI_1234"

        // Expand a reference into a URI
        String uri3 = converter.expand(reference);
        // "http://purl.obolibrary.org/obo/CHEBI_1234"

        // Compress a URI to a CURIE string
        String curie1 = converter.compress(uri);
        // CHEBI:1234

        // Parse a URI into a reference
        Reference reference1 = converter.parseURI(uri);
        // new Reference("CHEBI", "1234")

        // Parse a CURIE into a reference
        Reference reference2 = converter.parseCURIE(curie);
        // new Reference("CHEBI", "1234")
    }
}

Loading a Prefix Map

import java.util.HashMap;
import java.util.Map;
import org.biopragmatics.curies.Converter;
import org.biopragmatics.curies.Loader;

class AdHocResourceDemo {
    public static void main(String[] args) {
        Map<String, String> prefixMap = new HashMap<>();
        prefixMap.put("OMIM", "https://omim.org/entry/");
        prefixMap.put("OMIMPS", "https://omim.org/phenotypicSeries/PS");
        prefixMap.put("Orphanet", "http://www.orpha.net/ORDO/Orphanet_");

        Converter converter = new Converter(prefixMap);
        converter.compress("http://www.orpha.net/ORDO/Orphanet_85163");
        // Orphabet:85163
    }
}

Loading an Extended Prefix Map

If you have the URL for an extended prefix map, you can do the following:

import org.biopragmatics.curies.Converter;
import org.biopragmatics.curies.Loader;

class RemoteResourceDemo {
    public static void main(String[] args) {
        String url = "https://raw.githubusercontent.com/biopragmatics/bioregistry/main/exports/contexts/bioregistry.epm.json";
        Converter converter = new Converter(Loader.getRecords(url));
        converter.compress("https://www.ebi.ac.uk/ols/ontologies/doid/terms?obo_id=DOID:1234");
        // doid:1234
    }
}

Similarly, if you have a file object, you can do:

import java.io.*;
import org.biopragmatics.curies.Converter;
import org.biopragmatics.curies.Loader;

class LocalResourceDemo {
    public static void main(String[] args) {
        File file = new File("/Users/cthoyt/dev/bioregistry/exporst/contexts/bioregistry.epm.json")
        Converter converter = new Converter(Loader.getRecords(file));
        converter.compress("https://www.ebi.ac.uk/ols/ontologies/doid/terms?obo_id=DOID:1234");
        // doid:1234
    }
}

Bioregistry Integration

The Bioregistry can be loaded over the web.

import org.biopragmatics.curies.Converter;

class CuriesDemo2 {
    public static void main(String[] args) {
        Converter converter = Converter.loadBioregistry();
        converter.compress("https://www.ebi.ac.uk/ols/ontologies/doid/terms?obo_id=DOID:1234");
        // doid:1234
    }
}

Installation

See https://central.sonatype.com/artifact/org.biopragmatics.curies/curies

Acknowledgements

Special thanks to Jonas Schaub for helping with packaging and deployment to Maven Central.

curies4j's People

Contributors

cthoyt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

curies4j's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.