Object *** is not contained in a resource.

本文解释了在使用EMF时遇到DanglingHREFException的原因及解决方案。为确保所有对象被正确序列化,需将其直接或间接包含在资源中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I get a DanglingHREFException: e.g., "org.eclipse.emf.ecore.xmi.DanglingHREFException: The object 'com.example.Foo@2f5dda ()' is not contained in a resource." What do I need to do?

All objects need to be contained by a resource in order to be serialized. That implies that for EObject x to be serialized, it must be the case that x.eResource() != null. The resource will be non-null if either x is directly contained by a resource, i.e., if for Resource r, r.getContents().contains(x), or if x has a container that in turn is contained by a resource, i.e., if for Resource r, r.getContents().contains(x.eContainer()). This definition is recursive. So an object must be contained by a resource directly, or indirectly by virtue of being part of a containment reference where, recursively, the container too must be contained by a resource.

So if you get the above exception, that means you have some object x contained by a resource r that refers to another object y, that is not directly or indirectly contained by any resource. It's possible to make the EReference feature used by x to refer to y be transient, so that it's not saved at all, or to make it a containment reference, so that y is contained by the same resource as x, but barring changes to the Ecore model itself, the one and only way to solve this problem is to add y to some resource, i.e., r.getContents().add(y), or to add/set it to some containment reference of an object z, i.e., z.getYs().add(y), where z is already contained by a resource, i.e., z.eResource() != null

 

转自:http://wiki.eclipse.org/index.php/EMF-FAQ#I_get_a_DanglingHREFException:_e.g..2C_.22org.eclipse.emf.ecore.xmi.DanglingHREFException:_The_object_.27com.example.Foo.402f5dda_.28.29.27_is_not_contained_in_a_resource..22_What_do_I_need_to_do.3F

 

Another example is the SRIOV_NET_VF resource class, which is provided by SRIOV-enabled network interface cards. In the case of multiple SRIOV-enabled NICs on a compute host, different qualitative traits may be tagged to each NIC. For example, the NIC called enp2s0 might have a trait “CUSTOM_PHYSNET_PUBLIC” indicating that the NIC is attached to a physical network called “public”. The NIC enp2s1 might have a trait “CUSTOM_PHYSNET_INTRANET” that indicates the NIC is attached to the physical network called “Intranet”. We need a way of representing that these NICs each provide SRIOV_NET_VF resources but those virtual functions are associated with different physical networks. In the resource providers data modeling, the entity which is associated with qualitative traits is the resource provider object. Therefore, we require a way of representing that the SRIOV-enabled NICs are themselves resource providers with inventories of SRIOV_NET_VF resources. Those resource providers are contained on a compute host which is a resource provider that has inventory records for other types of resources such as VCPU, MEMORY_MB or DISK_GB. This spec proposes that nested resource providers be created to allow for distinguishing details of complex components of some resource providers. During review the question came up about “rolling up” amounts of these nested providers to the root level. Imagine this scenario: I have a NIC with two PFs, each of which has only 1 VF available, and I get a request for 2 VFs without any traits to distinguish them. Since there is no single resource provider that can satisfy this request, it will not select this root provider, even though the root provider “owns” 2 VFs. This spec does not propose any sort of “rolling up” of inventory, but this may be something to consider in the future. If it is an idea that has support, another BP/spec can be created then to add this behavior.
07-23
<think>嗯,用户的问题是关于如何验证一行数据是否未被包含在表格中。首先,我需要理解用户的具体需求。他们可能在处理大量数据时,需要确保某些行没有被重复录入或者遗漏。常见的情况可能是在数据合并、数据清洗或者数据验证的时候需要这样的检查。 接下来,我要考虑不同的工具和方法。用户提到了Excel和Python的Pandas,可能他们常用的工具是这两种。首先,针对Excel,我记得数据验证功能可以用来限制输入,但直接验证是否存在某一行可能需要其他方法。比如使用COUNTIF函数来统计某行是否存在。或者用条件格式来高亮显示重复项,但用户需要的是验证不包含,所以可能需要相反的操作。例如,如果COUNTIF返回0,则表示该行不存在。不过,处理整行的比较可能需要数组公式,比如用SUMPRODUCT或者EXACT函数结合数组操作,但Excel中处理整行匹配比较麻烦,可能需要逐列比较然后相乘结果。 然后是Python的Pandas,这部分应该更灵活一些。Pandas的isin方法可以检查每个元素是否在数据框中,但同样,整行的匹配可能需要结合all(axis=1)或者使用merge的方法。比如,将目标行转换为一个DataFrame,然后与原数据合并,查看是否有匹配的行。或者使用apply函数逐行比较。 还需要考虑用户提到的引用内容。引用[1]提到了在Excel中导入数据时的问题,合并单元格可能导致数据处理困难,所以在验证的时候需要注意数据结构是否规范,是否有合并单元格影响验证结果。引用[2]关于数据验证,可能可以设置自定义公式来检查是否存在。引用[3]提到的Pandas处理数据的方法,应该用isin、merge或者布尔索引。引用[4]中的CONCATENATE函数可能可以将多行合并成一行,但这里可能需要相反的操作,将多列合并成一个键来比较。 然后,用户可能遇到的困难点在于如何将一整行数据作为一个整体来比较。在Excel中,可能需要将多列的值连接成一个字符串,然后比较这个字符串是否存在于另一个区域。比如用&连接各列,然后用COUNTIF检查是否存在。或者使用数组公式,比如用SUMPRODUCT((A2:C10=D2)*(A2:C10=E2)*(A2:C10=F2)),但这样的公式如果列数多的话会很麻烦。 在Pandas中,可能需要将目标行转换为一个Series,然后使用isin方法,但isin是按元素而非按行。正确的方法应该是使用merge或者逐行比较。比如,使用df.merge(target_row, on=所有列名),如果结果不为空,则存在。或者使用df.apply(lambda row: row.equals(target_row), axis=1),然后检查是否有True。 另外,要注意数据类型的一致性,比如数字和文本的差异,或者空格、大小写等问题,这些可能导致误判。所以在比较前需要确保数据格式一致。 用户可能还需要一些示例代码或者步骤说明,所以需要给出具体的操作步骤,比如Excel中使用辅助列连接各列,然后用VLOOKUP或COUNTIF;Pandas中使用merge或布尔条件。 最后,生成相关问题的时候,需要考虑用户可能进一步的问题,比如如何处理大小写差异、如何高效处理大数据量的验证、或者如何删除重复行等。</think>### 如何验证一行数据是否未被包含在表格中? #### 方法一:Excel操作 1. **使用公式验证整行是否存在** 假设需要验证的表格范围为$A2:C10$,目标行为$D2:F2$(假设D、E、F列存储待验证数据): - 在空白单元格输入公式: ```excel =SUMPRODUCT(($A$2:$A$10=D2)*($B$2:$B$10=E2)*($C$2:$C$10=F2))=0 ``` 若结果为`TRUE`,表示该行未被包含在表格中[^2]。 2. **利用条件格式高亮重复行** - 选中待验证区域$A2:C10$,点击【条件格式】→【新建规则】→【使用公式确定格式】。 - 输入公式: ```excel =AND($A2=D$2, $B2=E$2, $C2=F$2) ``` 设置填充颜色后,若目标行无高亮,则表示未被包含[^4]。 --- #### 方法二:Python Pandas操作 ```python import pandas as pd # 读取表格数据 df = pd.read_excel("data.xlsx") target_row = pd.Series({"列1": "值1", "列2": "值2", "列3": "值3"}) # 检查是否存在 is_new = ~df.isin(target_row).all(axis=1).any() print("目标行未被包含" if is_new else "目标行已存在") ``` **解释**: - `df.isin(target_row)`逐列匹配目标值,`.all(axis=1)`判断是否整行匹配,`.any()`检查是否存在至少一个匹配项[^3]。 --- #### 注意事项 1. **数据规范性**:避免合并单元格或非二维数据布局,否则可能影响验证结果[^1]。 2. **数据类型一致性**:确保数值、文本等格式完全一致,例如`"100"`与`100`会被视为不同值。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值