Skip to content

Commit ff8c61f

Browse files
authored
Fixing a few configuration bugs (#541)
* Add excpetions when there are types not defined * should not include pdb * various small bug fixes * small fixes
1 parent 9170f30 commit ff8c61f

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

forte/data/caster.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def cast(self, pack: DataPack) -> MultiPack:
5454
Returns: An iterator that produces the boxed multi pack.
5555
5656
"""
57-
p = MultiPack()
57+
pack_name = pack.pack_name + "_multi" if pack.pack_name else None
58+
p = MultiPack(pack_name=pack_name)
5859
p.add_pack_(pack, self.configs.pack_name)
5960
return p
6061

forte/data/multi_pack.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def get_span_text(self, begin: int, end: int):
176176
"specific data pack to get text."
177177
)
178178

179-
def add_pack(self, ref_name: Optional[str] = None) -> DataPack:
179+
def add_pack(
180+
self, ref_name: Optional[str] = None, pack_name: Optional[str] = None
181+
) -> DataPack:
180182
"""
181183
Create a data pack and add it to this multi pack. If `ref_name` is
182184
provided, it will be used to index the data pack. Otherwise, a default
@@ -185,7 +187,9 @@ def add_pack(self, ref_name: Optional[str] = None) -> DataPack:
185187
186188
Args:
187189
ref_name (str): The pack name used to reference this data pack from
188-
the multi pack.
190+
the multi pack. If none, the reference name will not be set.
191+
pack_name (str): The pack name of the data pack (itself). If none,
192+
the name will not be set.
189193
190194
Returns: The newly created data pack.
191195
@@ -199,7 +203,7 @@ def add_pack(self, ref_name: Optional[str] = None) -> DataPack:
199203
f"{type(ref_name)}"
200204
)
201205

202-
pack: DataPack = DataPack()
206+
pack: DataPack = DataPack(pack_name=pack_name)
203207
self.add_pack_(pack, ref_name)
204208
return pack
205209

forte/data/ontology/ontology_code_generator.py

+8
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,14 @@ def parse_entry(
10491049
constraint_type_
10501050
)
10511051

1052+
if constraint_type_name is None:
1053+
raise TypeNotDeclaredException(
1054+
f"The type {constraint_type_} is not defined but it is "
1055+
f"specified in {schema_key} of the definition of "
1056+
f"{schema['entry_name']}. Please define them before "
1057+
f"this entry type."
1058+
)
1059+
10521060
# TODO: cannot handle constraints that contain self-references.
10531061
# self_ref = entry_name.class_name == constraint_type_
10541062

forte/pipeline.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
"""
1717

1818
import itertools
19-
import logging
2019
import json
21-
from time import time
20+
import logging
2221
import sys
23-
22+
from time import time
2423
from typing import (
2524
Any,
2625
Dict,
@@ -34,8 +33,8 @@
3433
Set,
3534
)
3635

37-
import yaml
3836
import uvicorn
37+
import yaml
3938
from fastapi import FastAPI
4039
from pydantic import BaseModel
4140

@@ -47,10 +46,10 @@
4746
)
4847
from forte.common.resources import Resources
4948
from forte.data.base_pack import PackType
50-
from forte.data.ontology.ontology_code_generator import OntologyCodeGenerator
51-
from forte.data.ontology.code_generation_objects import EntryTree
5249
from forte.data.base_reader import BaseReader
5350
from forte.data.caster import Caster
51+
from forte.data.ontology.code_generation_objects import EntryTree
52+
from forte.data.ontology.ontology_code_generator import OntologyCodeGenerator
5453
from forte.data.selector import Selector, DummySelector
5554
from forte.evaluation.base.base_evaluator import Evaluator
5655
from forte.pipeline_component import PipelineComponent
@@ -301,7 +300,9 @@ def init_from_config(self, configs: Dict[str, Any]):
301300
class_name=selector_config["type"],
302301
class_args=selector_config.get("kwargs", {}),
303302
),
304-
selector_config=selector_config.get("configs"),
303+
selector_config=None
304+
if selector_config is None
305+
else selector_config.get("configs"),
305306
)
306307

307308
# Set pipeline states and resources

forte/processors/base/pack_processor.py

-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Processors that process pack.
1616
"""
1717
from abc import ABC
18-
from typing import Optional
1918

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

5049
def _process(self, input_pack: MultiPack):
5150
raise NotImplementedError
52-
53-
def new_data_pack(self, pack_name: Optional[str] = None) -> DataPack:
54-
"""
55-
Create a new data pack using the current pack manager.
56-
57-
Args:
58-
pack_name (str, Optional): The name to be used for the pack. If not
59-
set, the pack name will remained unset.
60-
61-
Returns:
62-
63-
"""
64-
return DataPack(pack_name)

forte/processors/base/writers.py

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from abc import abstractmethod, ABC
2222
from typing import Optional, Any, Dict
2323

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

187+
if self.configs.output_dir is None:
188+
raise ProcessorConfigError(
189+
"`output_dir` is not specified for the writer."
190+
)
191+
186192
pack_paths = os.path.join(self.configs.output_dir, self.pack_idx)
187193
ensure_dir(pack_paths)
188194
self.pack_idx_out = open(pack_paths, "w", encoding="utf-8")

0 commit comments

Comments
 (0)