获取.owl文件的所有类的问题

问题描述 投票:0回答:1

我正在尝试在文本文件中写入.owl文件的所有类。但是我也收到很多不必要的东西。

我想摆脱诸如:untitled-ontology之类的术语。

untitled-ontology-17.Radiometry keep only Radiometry

And get rid of entire term such as OPB.OPB.somenumber

以下是我的代码:

onto=get_ontology("file:///Users/adarshkumar/Downloads/ontology.owl").load()
with onto:
    l=list(onto.classes())
    with open('entities.txt', 'w') as f:
            for i in l:
                if isinstance(i, ThingClass):
                    f.write("%s\n"%i)

这是我得到的输出的一部分(由于大小限制,大部分已经兴高采烈了:]

untitled-ontology-17.Radiometry
untitled-ontology-17.Astrophysics
untitled-ontology-17.Astronomical_Instruments
ontology.Bar_Magnet
ontology.Magnetic_Field_Sources
untitled-ontology-17.Magnetic_Field
ontology.Charge_Carriers
OPB.OPB_01476
ontology.Cyclotron
ontology.Electric_Motor
ontology.Galvanometer
untitled-ontology-17.Moving_Coil_Meters
ontology.Generator
ontology.Hall_Effect
ontology.Loudspeaker
ontology.Magnetic_Field_Plots
ontology.Magnetic_Flux
untitled-ontology-17.Faraday's_Law
ontology.Magnetic_Force
OPB.Non-Contact_Force
ontology.Magnetic_Moment
ontology.Magnetic_Permeability
ontology.Magnetic_Torque
OPB.Torque
ontology.Magnetohydrodynamics
ontology.Mass_Spectrometer
ontology.Microphone
ontology.Solenid
OPB.Absolute_Pressure
OPB.Pressure
OPB.Absolute_Temperature
OPB.Temperature
OPB.Absorption
OPB.Atomic_Properties
OPB.Acceleration
OPB.Adhesive_Force
OPB.Adiabatic_Condition
OPB.Adiabatic_Process
OPB.Heat_Engine_Processes
untitled-ontology-17.Speed_of_Sound
OPB.Specific_Heat
OPB.Air_Bag
OPB.Air_and_Water_Mattress
OPB.Air_Conditioners
OPB.Heat_pump
OPB.Air_Drag
OPB.Air_Friction
OPB.Terminal_Velocity
OPB.Friction
OPB.Air_Resistance
OPB.2nd_Equation_of_Motion
OPB.3rd_Equation_of_Motion
OPB.Avogadro's_Law
OPB.Boyle's_Law
OPB.Center_of_Mass:_Continuous
OPB.Charles'_Law
OPB.Sun's_Tidal_Effect
OPB.The_Baby's_First_Breath
OPB.W_=_Fx
OPB.Wien's_Displacement_Law
OPB.Young's_Modulus
untitled-ontology-17.ACS
untitled-ontology-17.Imaging_Systems
untitled-ontology-17.AC_Circuits
untitled-ontology-17.Electric_Circuits

我为什么得到那个17.classname?为什么17?

如何获得诸如“放射线学,天体物理学等”之类的简单术语?

非常感谢您的帮助。

python python-3.x ontology protege owlready
1个回答
0
投票

尝试一下:

onto=get_ontology("file:///Users/adarshkumar/Downloads/ontology.owl").load()
with onto:
    l=list(onto.classes())
    with open('entities.txt', 'w') as f:
            for i in l:
                blacklist = ["Radiometry", "Astrophysics"]
                for itm in blacklist:
                    if itm in str(i):
                        continue
                if isinstance(i, ThingClass):
                    f.write("%s\n"%i)
© www.soinside.com 2019 - 2024. All rights reserved.