示例#1
0
 def named_contexts(self) -> Dict[str, LDContext]:
     """Reusable named contexts."""
     return {
         'github-generated':
         as_document(URL('file://',
                         self.plugin_data_dir / 'gh-auto.yaml'), ),
         'github':
         as_document(URL('file://', self.plugin_data_dir / 'gh.yaml'), ),
     }
示例#2
0
 def named_contexts(self) -> Dict[str, LDContext]:
     """Reusable named contexts."""
     return {
         'prov': as_document(
             URL('file://', self.plugin_data_dir / 'named-context.yaml'),
         ),
     }
示例#3
0
def test_read_context():
    """Make sure that we can read the YAML context correctly."""
    path = Path(octadocs.__file__).parent / 'yaml/context.yaml'
    url = path_to_url(path)
    document = as_document(url)

    assert document['@base'] == 'local:'
    assert document['@vocab'] == 'local:'
    assert document['title'] == 'octa:title'
示例#4
0
    def on_config(self, config: Config) -> Config:
        """Initialize Octiron and provide graph to macros through the config."""
        docs_dir = Path(config['docs_dir'])

        self.octiron = cached_octiron(
            docs_dir=docs_dir,
        )

        self.stored_query = StoredQuery(
            path=docs_dir.parent / 'queries',
            executor=partial(
                query,
                instance=self.octiron.graph,
            ),
        )

        if config['extra'] is None:
            config['extra'] = {}  # type: ignore

        config['extra'].update({
            'graph': self.octiron.graph,
            'octiron': self.octiron,
            'queries': self.stored_query,
            'named_contexts': {
                'rdfs': as_document(
                    URL(
                        'file://',
                        Path(__file__).parent / 'data/rdfs/named-context.json',
                    ),
                ),
                'iolanta': as_document(
                    URL(
                        'file://',
                        Path(
                            __file__,
                        ).parent / 'data/iolanta/named-context.json',
                    ),
                ),
            },
        })

        return config
示例#5
0
def construct_root_context(namespaces: Dict[str, Namespace]) -> LDDocument:
    """
    Construct default JSON-LD context for all Octadocs data.

    This context contains:
        - declarations for all namespaces,
        - plus content of the default `context.yaml`.
    """
    namespaces_context = {
        prefix: str(namespace)
        for prefix, namespace in namespaces.items() if prefix
    }
    document_context = as_document(
        path_to_url(Path(__file__).parent / 'yaml/context.yaml', ), )

    return {
        **namespaces_context,
        **document_context,
    }