Skip to content

Fixing a few configuration bugs #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion forte/data/caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def cast(self, pack: DataPack) -> MultiPack:
Returns: An iterator that produces the boxed multi pack.

"""
p = MultiPack()
pack_name = pack.pack_name + "_multi" if pack.pack_name else None
p = MultiPack(pack_name=pack_name)
p.add_pack_(pack, self.configs.pack_name)
return p

Expand Down
10 changes: 7 additions & 3 deletions forte/data/multi_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def get_span_text(self, begin: int, end: int):
"specific data pack to get text."
)

def add_pack(self, ref_name: Optional[str] = None) -> DataPack:
def add_pack(
self, ref_name: Optional[str] = None, pack_name: Optional[str] = None
) -> DataPack:
"""
Create a data pack and add it to this multi pack. If `ref_name` is
provided, it will be used to index the data pack. Otherwise, a default
Expand All @@ -185,7 +187,9 @@ def add_pack(self, ref_name: Optional[str] = None) -> DataPack:

Args:
ref_name (str): The pack name used to reference this data pack from
the multi pack.
the multi pack. If none, the reference name will not be set.
pack_name (str): The pack name of the data pack (itself). If none,
the name will not be set.

Returns: The newly created data pack.

Expand All @@ -199,7 +203,7 @@ def add_pack(self, ref_name: Optional[str] = None) -> DataPack:
f"{type(ref_name)}"
)

pack: DataPack = DataPack()
pack: DataPack = DataPack(pack_name=pack_name)
self.add_pack_(pack, ref_name)
return pack

Expand Down
8 changes: 8 additions & 0 deletions forte/data/ontology/ontology_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,14 @@ def parse_entry(
constraint_type_
)

if constraint_type_name is None:
raise TypeNotDeclaredException(
f"The type {constraint_type_} is not defined but it is "
f"specified in {schema_key} of the definition of "
f"{schema['entry_name']}. Please define them before "
f"this entry type."
)

# TODO: cannot handle constraints that contain self-references.
# self_ref = entry_name.class_name == constraint_type_

Expand Down
15 changes: 8 additions & 7 deletions forte/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
"""

import itertools
import logging
import json
from time import time
import logging
import sys

from time import time
from typing import (
Any,
Dict,
Expand All @@ -34,8 +33,8 @@
Set,
)

import yaml
import uvicorn
import yaml
from fastapi import FastAPI
from pydantic import BaseModel

Expand All @@ -47,10 +46,10 @@
)
from forte.common.resources import Resources
from forte.data.base_pack import PackType
from forte.data.ontology.ontology_code_generator import OntologyCodeGenerator
from forte.data.ontology.code_generation_objects import EntryTree
from forte.data.base_reader import BaseReader
from forte.data.caster import Caster
from forte.data.ontology.code_generation_objects import EntryTree
from forte.data.ontology.ontology_code_generator import OntologyCodeGenerator
from forte.data.selector import Selector, DummySelector
from forte.evaluation.base.base_evaluator import Evaluator
from forte.pipeline_component import PipelineComponent
Expand Down Expand Up @@ -301,7 +300,9 @@ def init_from_config(self, configs: Dict[str, Any]):
class_name=selector_config["type"],
class_args=selector_config.get("kwargs", {}),
),
selector_config=selector_config.get("configs"),
selector_config=None
if selector_config is None
else selector_config.get("configs"),
)

# Set pipeline states and resources
Expand Down
14 changes: 0 additions & 14 deletions forte/processors/base/pack_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Processors that process pack.
"""
from abc import ABC
from typing import Optional

from forte.data.base_pack import PackType
from forte.data.data_pack import DataPack
Expand Down Expand Up @@ -49,16 +48,3 @@ class MultiPackProcessor(BasePackProcessor[MultiPack], ABC):

def _process(self, input_pack: MultiPack):
raise NotImplementedError

def new_data_pack(self, pack_name: Optional[str] = None) -> DataPack:
"""
Create a new data pack using the current pack manager.

Args:
pack_name (str, Optional): The name to be used for the pack. If not
set, the pack name will remained unset.

Returns:

"""
return DataPack(pack_name)
6 changes: 6 additions & 0 deletions forte/processors/base/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from abc import abstractmethod, ABC
from typing import Optional, Any, Dict

from forte.common import ProcessorConfigError
from forte.common.configuration import Config
from forte.common.resources import Resources
from forte.data.base_pack import BasePack
Expand Down Expand Up @@ -183,6 +184,11 @@ def initialize(self, resources: Resources, configs: Config):
# pylint: disable=attribute-defined-outside-init,consider-using-with
super().initialize(resources, configs)

if self.configs.output_dir is None:
raise ProcessorConfigError(
"`output_dir` is not specified for the writer."
)

pack_paths = os.path.join(self.configs.output_dir, self.pack_idx)
ensure_dir(pack_paths)
self.pack_idx_out = open(pack_paths, "w", encoding="utf-8")
Expand Down