Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ src/osw/model/*.json
playground

.env

# Automatically added by osw.auth.CredentialManager.save_credentials_to_file:
*/osw_files/*
3 changes: 3 additions & 0 deletions examples/.env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OSW_DOMAIN=wiki-dev.open-semantic-lab.org
OSW_CRED_FILEPATH=/path/to/credentials/file
OSW_DOWNLOAD_DIR=/path/to/download/directory
4 changes: 2 additions & 2 deletions examples/controller_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing_extensions import override

from osw.controller.entity import Entity, Hardware
from osw.controller.entity import Entity
from osw.express import OswExpress

# Create/update the password file under examples/accounts.pwd.yaml
Expand All @@ -18,7 +18,7 @@
osw_obj.fetch_schema(
fetchSchemaParam=OswExpress.FetchSchemaParam(schema_title="Category:Hardware")
)

from osw.model.entity import Hardware # noqa: E402

title = "Item:OSW7d7193567ea14e4e89b74de88983b718"
# title = "Item:OSWe02213b6c4664d04834355dc8eb08b99"
Expand Down
3 changes: 2 additions & 1 deletion examples/create_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import osw.model.entity as model

my_entity = model.Item(
label=[model.Label(text="MyItem")], statements=[model.Statement(predicate="IsA")]
label=[model.Label(text="MyItem")],
statements=[model.DataStatement(property="IsA", value="Category:Item")],
)
pprint(my_entity.dict())
print(my_entity.json())
6 changes: 3 additions & 3 deletions examples/device_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
model, "Corporation"
): # only load if not already loaded. note: does not detect updated schemas yet
DEPENDENCIES = {
"MetaDeviceCategory": "Category:OSWd845b96813a344458f140e48c4d063fd",
"DeviceType": "Category:OSWd845b96813a344458f140e48c4d063fd",
"Device(SubclassWithMetaModel)": "Category:OSW5bf1542d9cf847db83cbc73d579ba9d6",
"Corporation": "Category:OSW5f4a3751d23e482d80fb0b72dcd6bc31", #
}
Expand All @@ -47,7 +47,7 @@
)

# Create a new device type with the new manufacturer as manufacturer
new_category = model.MetaDeviceCategory( # here used as a device type
new_category = model.DeviceType( # here used as a device type
uuid=uuid.uuid5(
uuid_namespace, "MyNewDeviceCategory"
), # use a stable id from the source dataset / file
Expand All @@ -70,7 +70,7 @@
namespace="Category",
# meta_category_title= (
# "Category:OSWd845b96813a344458f140e48c4d063fd")
# usage of MetaDeviceCategory not yet supported
# usage of DeviceType not yet supported
)
)

Expand Down
1 change: 1 addition & 0 deletions examples/generate_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# load dependencies
DEPENDENCIES = {
"Tool": "Category:OSWe427aafafbac4262955b9f690a83405d",
"Device": "Category:OSWf0fe562f422d49c6877490b3dfee2f3f",
}
osw_obj.install_dependencies(DEPENDENCIES, mode="append", policy="if-missing")

Expand Down
4 changes: 4 additions & 0 deletions examples/get_page_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
go to special pages -> Bot passwords ; follow the instructions)
"""

import dotenv

from osw.express import OswExpress
from osw.params import GetPageParam

dotenv.load_dotenv()

osw = OswExpress(domain="demo.open-semantic-lab.org")

# the page title of the page to downlaod
Expand Down
2 changes: 1 addition & 1 deletion examples/inter_osw_copy_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from pathlib import Path

from opensemantic.v1 import OswBaseModel
from typing_extensions import List, Optional, Union

from osw.auth import CredentialManager
from osw.core import OSW
from osw.model.static import OswBaseModel
from osw.utils import util
from osw.wtsite import SLOTS, WtPage, WtSite

Expand Down
4 changes: 4 additions & 0 deletions examples/offline_content_package.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import os
from pathlib import Path

import dotenv

from osw import wiki_tools
from osw.auth import CredentialManager
from osw.core import OSW
from osw.model.page_package import PagePackage, PagePackageBundle, PagePackageConfig
from osw.params import CreatePagePackageParam, PageDumpConfig
from osw.wtsite import WtSite

dotenv.load_dotenv()
Comment thread
LukasGold marked this conversation as resolved.

# Create/update the password file under examples/accounts.pwd.yaml
pwd_file_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "accounts.pwd.yaml"
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/query_minimal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import dotenv

from osw.express import OswExpress

dotenv.load_dotenv()

# Create an OswExpress object
domain = "wiki-dev.open-semantic-lab.org"
osw = OswExpress(domain=domain)
Expand Down
4 changes: 1 addition & 3 deletions examples/register_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from typing import ClassVar
from uuid import uuid4

from pydantic.v1 import BaseModel

import osw.model.entity as model
from osw.core import OSW
from osw.express import OswExpress
Expand All @@ -20,7 +18,7 @@

# todo: does dataclass export only most specific class jsonschema
class MyPythonClass(
BaseModel
model.OswBaseModel
): # We don't inherit from model.Item here because this will trigger a full schema
# export
__uuid__: ClassVar[uuid4] = "23e4356e-b726-4c5b-b63f-620b301eb836"
Expand Down
3 changes: 2 additions & 1 deletion examples/store_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
)

my_entity = model.Item(
label=[model.Label(text="MyItem")], statements=[model.Statement(predicate="IsA")]
label=[model.Label(text="MyItem")],
statements=[model.DataStatement(property="IsA", value="Category:Item")],
)
pprint(my_entity)

Expand Down
22 changes: 13 additions & 9 deletions examples/use_express_functions.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import os
from pathlib import Path

from osw.defaults import params as default_params
from osw.defaults import paths as default_paths

# The domain, osw.express will be initialized with
default_params.wiki_domain = "wiki-dev.open-semantic-lab.org"
import dotenv

from osw.express import OswExpress, osw_download_file, osw_upload_file # noqa: E402

# Best practise load environment variables from .env file
dotenv.load_dotenv() # will look for a .env file in CWD and above

# (Alternative) Setting the domain of the wiki to connect to
os.environ["OSW_DOMAIN"] = "wiki-dev.open-semantic-lab.org"
# (Optional) Set the default credentials filepath to desired location. Otherwise,
# it will use the default location (current working directory)
# cred_filepath_default.set_default(r"C:\Users\gold\ownCloud\Personal\accounts.pwd.yaml")

# Check setting
print(f"Credentials loaded from '{str(default_paths.cred_filepath)}'")
os.environ["OSW_CRED_FILEPATH"] = str(
Path(__file__).parent / "osw_files" / "accounts.pwd.yaml"
)

# The domain to connect to
domain = "wiki-dev.open-semantic-lab.org"
# domain = "demo.open-semantic-lab.org"
# Create an OswExpress object
osw_obj = OswExpress(domain=domain)

# (Alternative, here equivalent to) loading domain from the environment variable
osw_obj = OswExpress()

# Create a file
fp = Path("example.txt")
with open(fp, "w") as file:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ package_dir =
=src

# Require a min/specific Python version (comma-separated conditions)
python_requires = >=3.10
python_requires = >=3.10, <3.14

# Add here dependencies of your project (line-separated), e.g. requests>=2.2,<3.0.
# Version specifiers like >=2.2,<3.0 avoid problems due to API changes in
Expand Down
Loading
Loading