How to use the ontospy.core.ontospy.Ontospy function in ontospy

To help you get started, we’ve selected a few ontospy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lambdamusic / Ontospy / ontospy / core / actions.py View on Github external
filename = location.split("/")[-1] or location.split("/")[-2]
                fullpath = ONTOSPY_LOCAL_MODELS + "/" + filename
                shutil.copy(location, fullpath)
            else:
                raise ValueError('The location specified is not a file.')
        # print("Saved local copy")
    except:
        printDebug(
            "Error retrieving file. Please make sure <%s> is a valid location."
            % location, "important")
        if os.path.exists(fullpath):
            os.remove(fullpath)
        return None

    try:
        g = Ontospy(fullpath, verbose=verbose)
        # printDebug("----------")
    except:
        g = None
        if os.path.exists(fullpath):
            os.remove(fullpath)
        printDebug(
            "Error parsing file. Please make sure %s contains valid RDF." %
            location, "important")

    if g:
        printDebug("Caching...", "red")
        do_pickle_ontology(filename, g)
        printDebug("----------\n...completed!", "important")

    # finally...
    return g
github lambdamusic / Ontospy / ontospy / xxx_main.py View on Github external
elif web:
        action_webimport()
        # raise SystemExit(1)

    elif shell:
        from extras.shell import launch_shell
        launch_shell(sources)

    else:
        if sources or (sources and endpoint):
            for x in sources:
                click.secho("Parsing %s..." % str(x), fg='white')

            if endpoint:
                g = Ontospy(sparql_endpoint=sources[0], verbose=verbose)
                printDebug("Extracting classes info")
                g.build_classes()
                printDebug("..done")
                printDebug("Extracting properties info")
                g.build_properties()
                printDebug("..done")
            else:
                g = Ontospy(uri_or_path=sources, verbose=verbose)

            shellPrintOverview(g, print_opts)

        else:
            click.echo(ctx.get_help())
            return

    # finally: print(some stats.... )
github lambdamusic / Ontospy / ontospy / core / actions.py View on Github external
Load up a model into ontospy and analyze it
    """
    for x in sources:
        click.secho("Parsing %s..." % str(x), fg='white')

    if extra:
        hide_base_schemas = False
        hide_implicit_types = False
        hide_implicit_preds = False
    else:
        hide_base_schemas = True
        hide_implicit_types = True
        hide_implicit_preds = True

    if raw:
        o = Ontospy(uri_or_path=sources, verbose=verbose, build_all=False)
        s = o.serialize()
        print(s)
        return
    elif endpoint:
        g = Ontospy(
            sparql_endpoint=sources[0],
            verbose=verbose,
            hide_base_schemas=hide_base_schemas,
            hide_implicit_types=hide_implicit_types,
            hide_implicit_preds=hide_implicit_preds)
        printDebug("Extracting classes info")
        g.build_classes()
        printDebug("..done")
        printDebug("Extracting properties info")
        g.build_properties()
        printDebug("..done")
github lambdamusic / Ontospy / ontospy / core / ontospy.py View on Github external
[1]123--
        [12]12--
        """
        TYPE_MARGIN = 13 # length for skos:concept

        if not element:	 # first time
            for x in self.toplayerSkosConcepts:
                printGenericTree(x, 0, showids, labels, showtype, TYPE_MARGIN)

        else:
            printGenericTree(element, 0, showids, labels, showtype, TYPE_MARGIN)




class SparqlEndpoint(Ontospy):
    """
    A remote graph accessible via a sparql endpoint
    """

    def __init__(self, source):
        """
        Init ontology object. Load the graph in memory, then setup all necessary attributes.
        """
        super(SparqlEndpoint, self).__init__(source, text=False, endpoint=True, rdf_format=None)
github lambdamusic / Ontospy / ontospy / core / actions.py View on Github external
ontouri = args[0]
        islocal = False

    # select a visualization
    if viztype:
        viztype = select_visualization(viztype)
    else:
        viztype = ask_visualization()
        if viztype == "":
            return None
        # raise SystemExit, 1

    # 2017-01-23: bypass pickled stuff as it has wrong counts etc..
    # get ontospy graph
    printDebug("Loading graph...", dim=True)
    g = Ontospy(ontouri, verbose=verbose)

    # put in home folder by default: //files..
    if not path:
        from os.path import expanduser
        home = expanduser("~")
        onto_path = slugify(unicode(ontouri))
        viz_path = slugify(unicode(VISUALIZATIONS_LIST[viztype]['Title']))
        path = os.path.join(home, "ontospy-viz/" + onto_path + "/" + viz_path)
        if not os.path.exists(path):
            os.makedirs(path)

    # url  = build_viz(ontouri, g, viztype, path)
    printDebug("Building visualization...", dim=True)
    url = build_visualization(ontouri, g, viztype, path, title, theme)

    return url
github lambdamusic / Ontospy / ontospy / core / ontospy.py View on Github external
def __init__(self, uri_or_path=None, text=None, file_obj=None, rdf_format="", verbose=True, hide_base_schemas=True):
        """
        Load the graph in memory, then setup all necessary attributes.
        """
        super(Ontospy, self).__init__()

        self.rdfgraph = None
        self.graphuri = None # needed?
        self.queryHelper = None 

        self.ontologies = []
        self.classes = []
        self.namespaces = []
        self.properties = []
        self.annotationProperties = []
        self.objectProperties = []
        self.datatypeProperties = []
        self.skosConcepts = []
        self.toplayer = []
        self.toplayerProperties = []
        self.toplayerSkosConcepts = []
github lambdamusic / Ontospy / ontospy / core / actions.py View on Github external
if extra:
        hide_base_schemas = False
        hide_implicit_types = False
        hide_implicit_preds = False
    else:
        hide_base_schemas = True
        hide_implicit_types = True
        hide_implicit_preds = True

    if raw:
        o = Ontospy(uri_or_path=sources, verbose=verbose, build_all=False)
        s = o.serialize()
        print(s)
        return
    elif endpoint:
        g = Ontospy(
            sparql_endpoint=sources[0],
            verbose=verbose,
            hide_base_schemas=hide_base_schemas,
            hide_implicit_types=hide_implicit_types,
            hide_implicit_preds=hide_implicit_preds)
        printDebug("Extracting classes info")
        g.build_classes()
        printDebug("..done")
        printDebug("Extracting properties info")
        g.build_properties()
        printDebug("..done")
    else:
        g = Ontospy(
            uri_or_path=sources,
            verbose=verbose,
            hide_base_schemas=hide_base_schemas,
github lambdamusic / Ontospy / ontospy / core / actions.py View on Github external
return
    elif endpoint:
        g = Ontospy(
            sparql_endpoint=sources[0],
            verbose=verbose,
            hide_base_schemas=hide_base_schemas,
            hide_implicit_types=hide_implicit_types,
            hide_implicit_preds=hide_implicit_preds)
        printDebug("Extracting classes info")
        g.build_classes()
        printDebug("..done")
        printDebug("Extracting properties info")
        g.build_properties()
        printDebug("..done")
    else:
        g = Ontospy(
            uri_or_path=sources,
            verbose=verbose,
            hide_base_schemas=hide_base_schemas,
            hide_implicit_types=hide_implicit_types,
            hide_implicit_preds=hide_implicit_preds)

    shellPrintOverview(g, print_opts)